saving data from dataset to an empty table

  • Thread starter Thread starter 2003et
  • Start date Start date
2

2003et

How to save data from a created dataset to an empty sqlserver table? tables
have identically the same schema.

Thanks,
 
Hi,

You will have to create a DataAdapter with InsertCommand SqlCommand object.
You'll also need an open SqlConnection assigned to InsertCommand.
To update the database, just call adapter.Update(dataset.Table);
It should work if table name and fields are the same.
If you want to, you can embed the Update call in a transaction.
Don't forget to close the connection afterwards.
 
2003et,

You will want to use the classes in the System.Data.SqlClient namespace.
You can use a SqlConnect object to get a connection to SQL server, and then
you can use the SqlDataAdapter to set up the commands to insert, update,
delete and select data from that table.

Then, you just have to add the rows to your table (so that the state is
seen as added) and then pass the dataset through to the SqlDataAdapter that
you created.

Hope this helps.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top