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'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 QianPlease mark the replies as answers if they help and unmark if they don't.
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'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 QianPlease mark the replies as answers if they help and unmark if they don't.