Best way to save a datatable into SQL server

J

John

Hi,

I have a datatable object in memory, the datasource is not from SQL server.
I want to save this datatable into SQL server 2000, what is the best way to
do it?

The only way I know is to create table dynamically then loop thru datatable
generate and execute an insert statement per row. Quite tedious.

TIA
 
N

Nicholas Paldino [.NET/C# MVP]

John,

You might have to create the table dynamically, but once you do that,
you should be able to create a SqlDataAdapter and pass the table to the
adapter with the InsertCommand set.

You will probably have to call the SetAdded method on each row of the
data table to set the row state to added (in case it was not), so that the
adapter will recognize the state as being changed.

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

Top