473,322 Members | 1,232 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

Error importing xml file

I am trying to export data from multiple tables in SQL Server to an XML file
so I can then import it to another database. It seems to be working fine for
exporting, but I am having trouble importing the file. I am getting the
following error trying to import the same xml file I just exported.
"System.Data.SqlClient.SqlException: Line 1: Incorrect syntax near
'GetTprsForExport'. Can someone show me where I am going wrong. Even though I
say the export is working, I am including it below in case there is something
in there that needs to be changed. Also, the code I am including is VERY
rough right now and will
change quite a bit once I figure out what I am doing. For the import, If I
understand it correctly, which I don't since I'm here :), I am supposed open
a dataset and then update it. Is that correct? If someone can show me where
I am going wrong and explain it, that would be great. Thanks in advance.

public static int Export()
{
string databaseName = HttpContext.Current.Session["DatabaseName"].ToString();
string connectionString =
ConfigurationSettings.AppSettings["DatabaseConnectionString"] + databaseName;
DataSet ds;

using (SqlConnection conn = new SqlConnection(connectionString))
{
DataTable dt = new DataTable();
SqlDataAdapter adapter = new SqlDataAdapter();

adapter.SelectCommand = new SqlCommand("GetTprsForExport", conn);
adapter.SelectCommand.CommandType = CommandType.StoredProcedure;

ds = new DataSet("TPRS");
adapter.Fill(ds, "Tprs");
}

DataRelation dr;
DataColumn parentCol;
DataColumn childCol;

parentCol = ds.Tables["Tprs"].Columns["TprID"];
childCol = ds.Tables["Tprs1"].Columns["TprID"];

dr = new DataRelation("TprAssociatedData", parentCol, childCol);

// Add the relation to the DataSet.
ds.Relations.Add(dr);

ds.WriteXml(@"D:\Data\test.xml", XmlWriteMode.WriteSchema);

return ds.Tables[0].Rows.Count;
}
public static int Import()
{
string databaseName = HttpContext.Current.Session["DatabaseName"].ToString();
string connectionString =
ConfigurationSettings.AppSettings["DatabaseConnectionString"] + databaseName;

using (SqlConnection conn = new SqlConnection(connectionString))
{
SqlDataAdapter adapter = new SqlDataAdapter();
adapter.SelectCommand = new SqlCommand("GetTprsForExport", conn);
SqlCommandBuilder builder = new SqlCommandBuilder(adapter);

DataSet ds = new DataSet("TPRS");
adapter.Fill(ds, "Tprs");

DataSet ds1 = new DataSet("TPRS");
ds1.ReadXml(@"D:\Data\test.xml", XmlReadMode.ReadSchema);

adapter.Update(ds1, "Tprs");
}

return 1;
}

Sep 1 '06 #1
5 2142
Mike,

I hope that you don't mind that I check completely your code, it is to long
for me, as far as I can see do I miss the line of code about this property.

http://msdn2.microsoft.com/en-us/lib...uringfill.aspx

That is mostly the first problem in this kind of situations.

I hope this helps,

Cor
"Mike Collins" <Mi*********@discussions.microsoft.comschreef in bericht
news:DA**********************************@microsof t.com...
>I am trying to export data from multiple tables in SQL Server to an XML
file
so I can then import it to another database. It seems to be working fine
for
exporting, but I am having trouble importing the file. I am getting the
following error trying to import the same xml file I just exported.
"System.Data.SqlClient.SqlException: Line 1: Incorrect syntax near
'GetTprsForExport'. Can someone show me where I am going wrong. Even
though I
say the export is working, I am including it below in case there is
something
in there that needs to be changed. Also, the code I am including is VERY
rough right now and will
change quite a bit once I figure out what I am doing. For the import, If I
understand it correctly, which I don't since I'm here :), I am supposed
open
a dataset and then update it. Is that correct? If someone can show me
where
I am going wrong and explain it, that would be great. Thanks in advance.

public static int Export()
{
string databaseName =
HttpContext.Current.Session["DatabaseName"].ToString();
string connectionString =
ConfigurationSettings.AppSettings["DatabaseConnectionString"] +
databaseName;
DataSet ds;

using (SqlConnection conn = new SqlConnection(connectionString))
{
DataTable dt = new DataTable();
SqlDataAdapter adapter = new SqlDataAdapter();

adapter.SelectCommand = new SqlCommand("GetTprsForExport", conn);
adapter.SelectCommand.CommandType = CommandType.StoredProcedure;

ds = new DataSet("TPRS");
adapter.Fill(ds, "Tprs");
}

DataRelation dr;
DataColumn parentCol;
DataColumn childCol;

parentCol = ds.Tables["Tprs"].Columns["TprID"];
childCol = ds.Tables["Tprs1"].Columns["TprID"];

dr = new DataRelation("TprAssociatedData", parentCol, childCol);

// Add the relation to the DataSet.
ds.Relations.Add(dr);

ds.WriteXml(@"D:\Data\test.xml", XmlWriteMode.WriteSchema);

return ds.Tables[0].Rows.Count;
}
public static int Import()
{
string databaseName =
HttpContext.Current.Session["DatabaseName"].ToString();
string connectionString =
ConfigurationSettings.AppSettings["DatabaseConnectionString"] +
databaseName;

using (SqlConnection conn = new SqlConnection(connectionString))
{
SqlDataAdapter adapter = new SqlDataAdapter();
adapter.SelectCommand = new SqlCommand("GetTprsForExport", conn);
SqlCommandBuilder builder = new SqlCommandBuilder(adapter);

DataSet ds = new DataSet("TPRS");
adapter.Fill(ds, "Tprs");

DataSet ds1 = new DataSet("TPRS");
ds1.ReadXml(@"D:\Data\test.xml", XmlReadMode.ReadSchema);

adapter.Update(ds1, "Tprs");
}

return 1;
}

Sep 2 '06 #2
Thanks, but one thing I found out is that I cannot expect to update the
database with the xml file when it contains multiple files. I believe I have
to enumerate through the file and call an update stored procedure for each
line. Is that correct?

"Cor Ligthert [MVP]" wrote:
Mike,

I hope that you don't mind that I check completely your code, it is to long
for me, as far as I can see do I miss the line of code about this property.

http://msdn2.microsoft.com/en-us/lib...uringfill.aspx

That is mostly the first problem in this kind of situations.

I hope this helps,

Cor
"Mike Collins" <Mi*********@discussions.microsoft.comschreef in bericht
news:DA**********************************@microsof t.com...
I am trying to export data from multiple tables in SQL Server to an XML
file
so I can then import it to another database. It seems to be working fine
for
exporting, but I am having trouble importing the file. I am getting the
following error trying to import the same xml file I just exported.
"System.Data.SqlClient.SqlException: Line 1: Incorrect syntax near
'GetTprsForExport'. Can someone show me where I am going wrong. Even
though I
say the export is working, I am including it below in case there is
something
in there that needs to be changed. Also, the code I am including is VERY
rough right now and will
change quite a bit once I figure out what I am doing. For the import, If I
understand it correctly, which I don't since I'm here :), I am supposed
open
a dataset and then update it. Is that correct? If someone can show me
where
I am going wrong and explain it, that would be great. Thanks in advance.

public static int Export()
{
string databaseName =
HttpContext.Current.Session["DatabaseName"].ToString();
string connectionString =
ConfigurationSettings.AppSettings["DatabaseConnectionString"] +
databaseName;
DataSet ds;

using (SqlConnection conn = new SqlConnection(connectionString))
{
DataTable dt = new DataTable();
SqlDataAdapter adapter = new SqlDataAdapter();

adapter.SelectCommand = new SqlCommand("GetTprsForExport", conn);
adapter.SelectCommand.CommandType = CommandType.StoredProcedure;

ds = new DataSet("TPRS");
adapter.Fill(ds, "Tprs");
}

DataRelation dr;
DataColumn parentCol;
DataColumn childCol;

parentCol = ds.Tables["Tprs"].Columns["TprID"];
childCol = ds.Tables["Tprs1"].Columns["TprID"];

dr = new DataRelation("TprAssociatedData", parentCol, childCol);

// Add the relation to the DataSet.
ds.Relations.Add(dr);

ds.WriteXml(@"D:\Data\test.xml", XmlWriteMode.WriteSchema);

return ds.Tables[0].Rows.Count;
}
public static int Import()
{
string databaseName =
HttpContext.Current.Session["DatabaseName"].ToString();
string connectionString =
ConfigurationSettings.AppSettings["DatabaseConnectionString"] +
databaseName;

using (SqlConnection conn = new SqlConnection(connectionString))
{
SqlDataAdapter adapter = new SqlDataAdapter();
adapter.SelectCommand = new SqlCommand("GetTprsForExport", conn);
SqlCommandBuilder builder = new SqlCommandBuilder(adapter);

DataSet ds = new DataSet("TPRS");
adapter.Fill(ds, "Tprs");

DataSet ds1 = new DataSet("TPRS");
ds1.ReadXml(@"D:\Data\test.xml", XmlReadMode.ReadSchema);

adapter.Update(ds1, "Tprs");
}

return 1;
}


Sep 2 '06 #3
Mike,

If you are updating with the update, than you are in fact only using an
insert. As soon as there is than a row that exist, than you are in problem,
because in your datarowstate is set that it is about a new row and than you
can have concurrency error or errors because that some fields have to be
unique in your database.

How to solve that is in my idea based on the solution that you want to
achieve.

Your dataset has to have of course exactly the same schema as the database
table.

Cor

"Mike Collins" <Mi*********@discussions.microsoft.comschreef in bericht
news:66**********************************@microsof t.com...
Thanks, but one thing I found out is that I cannot expect to update the
database with the xml file when it contains multiple files. I believe I
have
to enumerate through the file and call an update stored procedure for each
line. Is that correct?

"Cor Ligthert [MVP]" wrote:
>Mike,

I hope that you don't mind that I check completely your code, it is to
long
for me, as far as I can see do I miss the line of code about this
property.

http://msdn2.microsoft.com/en-us/lib...uringfill.aspx

That is mostly the first problem in this kind of situations.

I hope this helps,

Cor
"Mike Collins" <Mi*********@discussions.microsoft.comschreef in bericht
news:DA**********************************@microso ft.com...
>I am trying to export data from multiple tables in SQL Server to an XML
file
so I can then import it to another database. It seems to be working
fine
for
exporting, but I am having trouble importing the file. I am getting
the
following error trying to import the same xml file I just exported.
"System.Data.SqlClient.SqlException: Line 1: Incorrect syntax near
'GetTprsForExport'. Can someone show me where I am going wrong. Even
though I
say the export is working, I am including it below in case there is
something
in there that needs to be changed. Also, the code I am including is
VERY
rough right now and will
change quite a bit once I figure out what I am doing. For the import,
If I
understand it correctly, which I don't since I'm here :), I am supposed
open
a dataset and then update it. Is that correct? If someone can show me
where
I am going wrong and explain it, that would be great. Thanks in
advance.

public static int Export()
{
string databaseName =
HttpContext.Current.Session["DatabaseName"].ToString();
string connectionString =
ConfigurationSettings.AppSettings["DatabaseConnectionString"] +
databaseName;
DataSet ds;

using (SqlConnection conn = new SqlConnection(connectionString))
{
DataTable dt = new DataTable();
SqlDataAdapter adapter = new SqlDataAdapter();

adapter.SelectCommand = new SqlCommand("GetTprsForExport", conn);
adapter.SelectCommand.CommandType = CommandType.StoredProcedure;

ds = new DataSet("TPRS");
adapter.Fill(ds, "Tprs");
}

DataRelation dr;
DataColumn parentCol;
DataColumn childCol;

parentCol = ds.Tables["Tprs"].Columns["TprID"];
childCol = ds.Tables["Tprs1"].Columns["TprID"];

dr = new DataRelation("TprAssociatedData", parentCol, childCol);

// Add the relation to the DataSet.
ds.Relations.Add(dr);

ds.WriteXml(@"D:\Data\test.xml", XmlWriteMode.WriteSchema);

return ds.Tables[0].Rows.Count;
}
public static int Import()
{
string databaseName =
HttpContext.Current.Session["DatabaseName"].ToString();
string connectionString =
ConfigurationSettings.AppSettings["DatabaseConnectionString"] +
databaseName;

using (SqlConnection conn = new SqlConnection(connectionString))
{
SqlDataAdapter adapter = new SqlDataAdapter();
adapter.SelectCommand = new SqlCommand("GetTprsForExport", conn);
SqlCommandBuilder builder = new SqlCommandBuilder(adapter);

DataSet ds = new DataSet("TPRS");
adapter.Fill(ds, "Tprs");

DataSet ds1 = new DataSet("TPRS");
ds1.ReadXml(@"D:\Data\test.xml", XmlReadMode.ReadSchema);

adapter.Update(ds1, "Tprs");
}

return 1;
}



Sep 2 '06 #4
I tried what you said, but I still get "Incorrect syntax neat
'GetTprsForExport'". I'm pretty stuck here.

"Cor Ligthert [MVP]" wrote:
Mike,

If you are updating with the update, than you are in fact only using an
insert. As soon as there is than a row that exist, than you are in problem,
because in your datarowstate is set that it is about a new row and than you
can have concurrency error or errors because that some fields have to be
unique in your database.

How to solve that is in my idea based on the solution that you want to
achieve.

Your dataset has to have of course exactly the same schema as the database
table.

Cor

"Mike Collins" <Mi*********@discussions.microsoft.comschreef in bericht
news:66**********************************@microsof t.com...
Thanks, but one thing I found out is that I cannot expect to update the
database with the xml file when it contains multiple files. I believe I
have
to enumerate through the file and call an update stored procedure for each
line. Is that correct?

"Cor Ligthert [MVP]" wrote:
Mike,

I hope that you don't mind that I check completely your code, it is to
long
for me, as far as I can see do I miss the line of code about this
property.

http://msdn2.microsoft.com/en-us/lib...uringfill.aspx

That is mostly the first problem in this kind of situations.

I hope this helps,

Cor
"Mike Collins" <Mi*********@discussions.microsoft.comschreef in bericht
news:DA**********************************@microsof t.com...
I am trying to export data from multiple tables in SQL Server to an XML
file
so I can then import it to another database. It seems to be working
fine
for
exporting, but I am having trouble importing the file. I am getting
the
following error trying to import the same xml file I just exported.
"System.Data.SqlClient.SqlException: Line 1: Incorrect syntax near
'GetTprsForExport'. Can someone show me where I am going wrong. Even
though I
say the export is working, I am including it below in case there is
something
in there that needs to be changed. Also, the code I am including is
VERY
rough right now and will
change quite a bit once I figure out what I am doing. For the import,
If I
understand it correctly, which I don't since I'm here :), I am supposed
open
a dataset and then update it. Is that correct? If someone can show me
where
I am going wrong and explain it, that would be great. Thanks in
advance.

public static int Export()
{
string databaseName =
HttpContext.Current.Session["DatabaseName"].ToString();
string connectionString =
ConfigurationSettings.AppSettings["DatabaseConnectionString"] +
databaseName;
DataSet ds;

using (SqlConnection conn = new SqlConnection(connectionString))
{
DataTable dt = new DataTable();
SqlDataAdapter adapter = new SqlDataAdapter();

adapter.SelectCommand = new SqlCommand("GetTprsForExport", conn);
adapter.SelectCommand.CommandType = CommandType.StoredProcedure;

ds = new DataSet("TPRS");
adapter.Fill(ds, "Tprs");
}

DataRelation dr;
DataColumn parentCol;
DataColumn childCol;

parentCol = ds.Tables["Tprs"].Columns["TprID"];
childCol = ds.Tables["Tprs1"].Columns["TprID"];

dr = new DataRelation("TprAssociatedData", parentCol, childCol);

// Add the relation to the DataSet.
ds.Relations.Add(dr);

ds.WriteXml(@"D:\Data\test.xml", XmlWriteMode.WriteSchema);

return ds.Tables[0].Rows.Count;
}
public static int Import()
{
string databaseName =
HttpContext.Current.Session["DatabaseName"].ToString();
string connectionString =
ConfigurationSettings.AppSettings["DatabaseConnectionString"] +
databaseName;

using (SqlConnection conn = new SqlConnection(connectionString))
{
SqlDataAdapter adapter = new SqlDataAdapter();
adapter.SelectCommand = new SqlCommand("GetTprsForExport", conn);
SqlCommandBuilder builder = new SqlCommandBuilder(adapter);

DataSet ds = new DataSet("TPRS");
adapter.Fill(ds, "Tprs");

DataSet ds1 = new DataSet("TPRS");
ds1.ReadXml(@"D:\Data\test.xml", XmlReadMode.ReadSchema);

adapter.Update(ds1, "Tprs");
}

return 1;
}



Sep 2 '06 #5
Mike,

Without that renewed code we can do nothing for you.

Cor

"Mike Collins" <Mi*********@discussions.microsoft.comschreef in bericht
news:1B**********************************@microsof t.com...
>I tried what you said, but I still get "Incorrect syntax neat
'GetTprsForExport'". I'm pretty stuck here.

"Cor Ligthert [MVP]" wrote:
>Mike,

If you are updating with the update, than you are in fact only using an
insert. As soon as there is than a row that exist, than you are in
problem,
because in your datarowstate is set that it is about a new row and than
you
can have concurrency error or errors because that some fields have to be
unique in your database.

How to solve that is in my idea based on the solution that you want to
achieve.

Your dataset has to have of course exactly the same schema as the
database
table.

Cor

"Mike Collins" <Mi*********@discussions.microsoft.comschreef in bericht
news:66**********************************@microso ft.com...
Thanks, but one thing I found out is that I cannot expect to update the
database with the xml file when it contains multiple files. I believe I
have
to enumerate through the file and call an update stored procedure for
each
line. Is that correct?

"Cor Ligthert [MVP]" wrote:

Mike,

I hope that you don't mind that I check completely your code, it is to
long
for me, as far as I can see do I miss the line of code about this
property.

http://msdn2.microsoft.com/en-us/lib...uringfill.aspx

That is mostly the first problem in this kind of situations.

I hope this helps,

Cor
"Mike Collins" <Mi*********@discussions.microsoft.comschreef in
bericht
news:DA**********************************@microso ft.com...
I am trying to export data from multiple tables in SQL Server to an
XML
file
so I can then import it to another database. It seems to be working
fine
for
exporting, but I am having trouble importing the file. I am getting
the
following error trying to import the same xml file I just exported.
"System.Data.SqlClient.SqlException: Line 1: Incorrect syntax near
'GetTprsForExport'. Can someone show me where I am going wrong. Even
though I
say the export is working, I am including it below in case there is
something
in there that needs to be changed. Also, the code I am including is
VERY
rough right now and will
change quite a bit once I figure out what I am doing. For the
import,
If I
understand it correctly, which I don't since I'm here :), I am
supposed
open
a dataset and then update it. Is that correct? If someone can show
me
where
I am going wrong and explain it, that would be great. Thanks in
advance.

public static int Export()
{
string databaseName =
HttpContext.Current.Session["DatabaseName"].ToString();
string connectionString =
ConfigurationSettings.AppSettings["DatabaseConnectionString"] +
databaseName;
DataSet ds;

using (SqlConnection conn = new SqlConnection(connectionString))
{
DataTable dt = new DataTable();
SqlDataAdapter adapter = new SqlDataAdapter();

adapter.SelectCommand = new SqlCommand("GetTprsForExport", conn);
adapter.SelectCommand.CommandType = CommandType.StoredProcedure;

ds = new DataSet("TPRS");
adapter.Fill(ds, "Tprs");
}

DataRelation dr;
DataColumn parentCol;
DataColumn childCol;

parentCol = ds.Tables["Tprs"].Columns["TprID"];
childCol = ds.Tables["Tprs1"].Columns["TprID"];

dr = new DataRelation("TprAssociatedData", parentCol, childCol);

// Add the relation to the DataSet.
ds.Relations.Add(dr);

ds.WriteXml(@"D:\Data\test.xml", XmlWriteMode.WriteSchema);

return ds.Tables[0].Rows.Count;
}
public static int Import()
{
string databaseName =
HttpContext.Current.Session["DatabaseName"].ToString();
string connectionString =
ConfigurationSettings.AppSettings["DatabaseConnectionString"] +
databaseName;

using (SqlConnection conn = new SqlConnection(connectionString))
{
SqlDataAdapter adapter = new SqlDataAdapter();
adapter.SelectCommand = new SqlCommand("GetTprsForExport", conn);
SqlCommandBuilder builder = new SqlCommandBuilder(adapter);

DataSet ds = new DataSet("TPRS");
adapter.Fill(ds, "Tprs");

DataSet ds1 = new DataSet("TPRS");
ds1.ReadXml(@"D:\Data\test.xml", XmlReadMode.ReadSchema);

adapter.Update(ds1, "Tprs");
}

return 1;
}




Sep 3 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: ekyungchung | last post by:
I did install the python 2.4 and nltk. I am trying to follow the tutorial, but I kept getting error messages about importing corpus as follows ===================================================...
0
by: Daryl Zavier | last post by:
Hi Gurus, Please forgive me if my question is dumb cause this is my first web application I've done. Currently in my web application there is a button to click which will fire off a DTS event...
11
by: Grim Reaper | last post by:
I am importing a .csv file into Access that has 37 fields. My problem is that sometimes the last field only has data at the end of the column (it looks like when you import a file into Access, for...
9
by: advance scout | last post by:
HELP! My database is suddenly corrupted. My computer was acting funny (very sluggish) and was shut down. Access had been already been closed down but computer was acting very slow , so perhaps it...
0
by: Alun Jones | last post by:
I'm getting the above error in a dialog box from Visual Studio 2005 when trying to sign an assembly using a PFX file, and would like to know how to resolve the problem. Background: The PFX...
1
by: puremetal33 | last post by:
I have worked very little with Access and have hit a snag. My task right now is to import the data from a spreadsheet into an existing table in an Access database. I edited the .xls file so that...
3
kickingthehabbit
by: kickingthehabbit | last post by:
Hi All new to all of this I just downloaded reactor server. everything works fine except Mysql - SQL import files. I am trying to import file createdb.sql I open DB and try and import with...
5
by: Marc Oldenhof | last post by:
Hello all, I'm pretty new to Python, but use it a lot lately. I'm getting a crazy error trying to do operations on a string list after importing numpy. Minimal example: Python 2.5.1...
6
by: passionateforjava | last post by:
Hi All, I am using struts application wherein I need to import file for some purpose.I have used input type="file" for the same which goes like: <input type="file" id="uploadFile" name="uploadFile"...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.