Joda Maki Joda Maki - 1 month ago 7
C# Question

Best way to Bulk Insert from a C# DataTable

I have a

DataTable
that I want to push to the DB. I want to be able to say like

myDataTable.update();


But after reading the MSDN docs, apparently this does inserts row by row.


It should be noted that these statements are not performed as a batch process; each row is updated individually.


What are my alternatives?

Edit: I am using SQL Server 2005

Answer

If using SQL Server, SqlBulkCopy.WriteToServer(DataTable)

Or also with SQL Server, you can write it to a .csv and use BULK INSERT

If using MySQL, you could write it to a .csv and use LOAD DATA INFILE

If using Oracle, you can use the array binding feature of ODP.NET

If SQLite:

Comments