I did some research over the web. Below are my understanding.
To update dataset to the database the typical method is to use SqlDataAdapter. But this requires to pass sql commands as well, at least SELECT statement with SqlCommandBuilder. Again SqlCommandBuilder is meant only for single-table updates. The example in this msdn link shows that =>
http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlcommandbuilder.aspxTo update multi-tables, using the same SqlDataAdapter/SqlCommandB
uilder, it should be updated table-by-table one adapter for each table. This link shows that =>
http://msdn.microsoft.com/en-us/library/4esb49b4(v=VS.80).aspxIf you have only few tables to update, then I would say to follow the methods above. Since the typed dataset has been created from the database its schema would match the database.
Alternatively you can directly import the xml data into database using SQL Server's BULK INSERT or OPENROWSET(BULKā¦) or bcp utility. Again the exampless I have seen so far deals with one table at a time. =>
http://msdn.microsoft.com/en-us/library/ms175915.aspxor if there is a third-party code library that scans the dataset and creates sqls and does the update, then that's what you are asking for. Basically 'update dataset to database without using sqldataadapter'. I will check and update if i find any such code.
or you can use other tools to export xml data to database like Altova DatabaseSpy, XMLSpy =>
http://www.altova.com/databasespy/database-import-export.htmlFor the basic single table update below code works for me:
DataSet dataSet;
// dataset is filled here
using (SqlConnection connection = new SqlConnection(connectionSt
ring))
{
SqlDataAdapter adapter = new SqlDataAdapter();
adapter.SelectCommand = new SqlCommand("SELECT col1, col2 FROM Table1", connection);
SqlCommandBuilder builder = new SqlCommandBuilder(adapter)
;
connection.Open();
builder.GetUpdateCommand()
;
adapter.Update(dataSet, tableName);
}
Regarding your notes on dataset and connection, dataset doesnot have or store connection details. that is its special feature (dis-connected nature). It is the SqlDataAdapter that uses the connection. Also I think the problem is the same whether it is dataset or typed dataset. Typed dataset just helps you to use it like a business object. Underlying commit taks is the same for both.
Hope this helps to show you some light.