Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bulk insert, asp.net

I have a need to take in a list of ID numbers corresponding to a member. Their can be anywhere from 10 to 10,000 being processed at any given time. I have no problem collecting the data, parsing the data and loading it in to a DataTable or anything (C#) but I want to do some operations in the database. What is the best way to insert all of this data into a table?

I am pretty sure I don't want run a for each statement and insert 10,000 times.

like image 219
dgxshiny Avatar asked May 17 '26 11:05

dgxshiny


2 Answers

I've used the SqlBulkCopy class before to do a couple million adds. It seemed pretty handy.

like image 110
Shea Daniels Avatar answered May 20 '26 01:05

Shea Daniels


You may not want to execute an INSERT 10,000 times, but you can wrap those 10,000 inserts into 1 transaction.

like image 44
JMP Avatar answered May 19 '26 23:05

JMP



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!