Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Fastest way Store data in database using c#

I have a csv file with 3 million lines and want to stored it in a database using c#. The csv file looks like "device;date;value".

Shall I write it into an array or directly into a System.Data.DataTable? And what is the fastest way to store this DataTable into a Database (SQL-Server for example).

I tried to store the lines using 3 million insert into statements but it was too slow :)

thanks

like image 924
user2110946 Avatar asked Aug 13 '26 03:08

user2110946


1 Answers

You can load the data in a DataTable and then use SqlBulkCopy for copying the date to the table in sql server

The SqlBulkCopy class can be used to write data only to SQL Server tables. However, the data source is not limited to SQL Server; any data source can be used, as long as the data can be loaded to a DataTable instance or read with a IDataReader instance. .

like image 111
Habib Avatar answered Aug 14 '26 17:08

Habib



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!