Insert from DataTable

N

Necqui Teja

Is there a quick and effcient way to insert records into SQL Server database
from a DataTable (DataTable dt;) when the DataTable and the SQL Server
database contain the same field names and attributes.

I'm using VS2005 Beta 2.

Thanks.
 
N

Nicholas Paldino [.NET/C# MVP]

Necqui,

The best way to do this would be to configure a SqlDataAdapter with the
appropriate InsertCommand (because you are adding records), and then pass
the DataTable to the Update method.

Hope this helps.
 
I

Ignacio Machin \( .NET/ C# MVP \)

Hi,

Where you get the data from?

You can check the DataRow.RowState to see the status of the row, then you
could run the required query (Update, Insert ) or as Paldino said use the
SqlDataAdapter.


cheers,
 

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