Windows Develop Bookmark and Share   
 index > Windows Forms Data Controls and Databinding > Move data from xml document to database table
 

Move data from xml document to database table

Hi,

I need to insert some data into database
This data is in xml file.
I moved it to dataset by using readxml method.
Now i have to move it to a table in database.

Any way to do this?
Thanks in Advance

rowter  Thursday, August 20, 2009 9:52 PM
Create a DataAdapter and Set the insert command for the adapter and update the database. Else you need to loop through the datatable rows and create insert insert statments
prasams  Friday, August 21, 2009 10:12 AM
Hi rowter,

prasams's suggestion is correct. You will have to put a loop throughout the rows of the datatable to build the insert sql. Then you can use SqlCommand.ExecuteNonQuery to execute the sql script. Here is the document of it.
http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlcommand.executenonquery.aspx

The queryString is what you need to build to insert new rows to the database. Then call the CreateCommand to pass the sql script and connection string to the database as the sample code shown.

If you have anything unclear with it, please feel free to tell me.

Sincerely,
Kira Qian
Please mark the replies as answers if they help and unmark if they don't.
Kira Qian  Monday, August 24, 2009 8:08 AM
Create a DataAdapter and Set the insert command for the adapter and update the database. Else you need to loop through the datatable rows and create insert insert statments
prasams  Friday, August 21, 2009 10:12 AM
Hi rowter,

prasams's suggestion is correct. You will have to put a loop throughout the rows of the datatable to build the insert sql. Then you can use SqlCommand.ExecuteNonQuery to execute the sql script. Here is the document of it.
http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlcommand.executenonquery.aspx

The queryString is what you need to build to insert new rows to the database. Then call the CreateCommand to pass the sql script and connection string to the database as the sample code shown.

If you have anything unclear with it, please feel free to tell me.

Sincerely,
Kira Qian
Please mark the replies as answers if they help and unmark if they don't.
Kira Qian  Monday, August 24, 2009 8:08 AM

You can use google to search for other answers

Custom Search

More Threads

• using datagridview bound to BindingSource (which is in turn bound to a datasource). Need to refresh datagridview automatically
• Can a custom DataGridView editing control change the value of more than one column ?
• Web Services as datasources
• Problem with datagrid view
• Reading an Excell file and closing it in C# VS2005
• raise event of data grid events - how to (force) call an event in datagrid
• DataGridView
• Invisible DataGridView - scroll problems
• putting focus on a particular cell in datagridview when user presses enter key
• datagridview, retrieve cell, simplest case