473,473 Members | 1,534 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Importing XML Data using a DataSet

I am importing a XML file and have not been having the best of luck in doing
this, but I do have the following solution below. I will not be importing
more than 2000 records at a time, but will be importing data to many
different tables. Can someone explain if there is a better way to do what I
am doing without having to call a stored procedure for each row (like I'm
doing below)? A good example would be great as my understanding of xml or
updating a disconnected dataset is not too good yet. I am using ADO.Net 1.1.
Thanks in advance.

public static int Import()
{

string databaseName =
HttpContext.Current.Session["DatabaseName"].ToString();
string connectionString =
ConfigurationSettings.AppSettings["DatabaseConnectionString"] + databaseName;

using (SqlConnection conn = new SqlConnection(connectionString))
{
DataSet ds = new DataSet();
ds.ReadXml(@"D:\Data\test.xml", XmlReadMode.ReadSchema);

foreach (DataTable table in ds.Tables)
{

for (int index = 0; index <= table.Rows.Count - 1; index++)
{
if (table.tableName == "Table1")
{
SqlCommand command = new SqlCommand("ImportDataForTable1", conn);
command.CommandType = CommandType.StoredProcedure;

SqlParameter param;
param = command.Parameters.Add("@recordID",
SqlDbType.UniqueIdentifier);
param.Value = new Guid(table.Rows[index]["RecordID"].ToString());

A bunch of other parameters...
}
else if (table.tableName == "table2")
{
SqlCommand command = new SqlCommand("ImportDataForTable2", conn);
command.CommandType = CommandType.StoredProcedure;

SqlParameter param;
param = command.Parameters.Add("@recordID",
SqlDbType.UniqueIdentifier);
param.Value = new Guid(table.Rows[index]["RecordID"].ToString());

A bunch of other parameters for Table 2...
}

conn.Open();
command.ExecuteNonQuery();
conn.Close();
}
}
}
}
Sep 5 '06 #1
0 1465

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

Similar topics

2
by: Lee Ottaway | last post by:
In order to achieve the archiving of old data from my database I have exported the information from my dataset to an XML file using the standard WriteXML method of the object. Now suppose in the...
3
by: James | last post by:
Hi, I'm importing some csv files with this code /// start of code snippet int iPos = strFileName.LastIndexOf(@"\"); string strPath = strFileName.Substring(0,iPos); string strSelect =...
5
by: Alex | last post by:
Hi, I have an aspx file that creates a custom class object and calls a method which should return a DataSet. It throws a: Description: The application attempted to perform an operation not...
1
by: Geoff Jones | last post by:
Hi I have a question which I hope somebody can answer. I have written a VB application with which I want to import an Excel file, analyze the data within it and do some calculations. There are...
0
by: Mike Collins | last post by:
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...
5
by: Mike Collins | last post by:
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...
2
by: Mike Collins | last post by:
I am importing a XML file and have not been having the best of luck in doing this, but I do have the following solution below. I will not be importing more than 2000 records at a time, but will be...
12
by: JMO | last post by:
I can import a csv file with no problem. I can also add columns to the datagrid upon import. I want to be able to start importing at the 3rd row. This will pick up the headers necessary for the...
0
by: tom | last post by:
When I try to read in a csv file it gives me this error message. 'Cannot update. Database or object is read-only.' If I change the extension to txt it processes just fine. I have googled all...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.