Adding datatable data to sql database.

V

Vaibhav

Hello everyone,

I have a datatable with rows read from csv file. Now i want to insert the
data from datatable to database. Datatable has same columns as the table to
which i have to add rows.

Can anyone tell me the way i can achieve this. The datatable is a normal
datatable and not table from a dataset.

Thanks in advance
 
F

Frank Uray

Hi

You can try this:

System.Data.SqlClient.SqlCommandBuilder local_SqlCommandBuilder = new
System.Data.SqlClient.SqlCommandBuilder(local_SqlDataAdapter);
local_SqlCommandBuilder.ConflictOption =
System.Data.ConflictOption.OverwriteChanges;
local_SqlDataAdapter.UpdateCommand =
local_SqlCommandBuilder.GetUpdateCommand();
local_SqlDataAdapter.Update(YourDataTable);

Best regards
Frank Uray
 

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