using (SqlBulkCopy bulkCopy = new SqlBulkCopy(connectionString, transaction)) { // SET BatchSize value. bulkCopy.BatchSize = 4000; bulkCopy.DestinationTableName = "TheDestinationTable"; bulkCopy.WriteToServer(dt); }
SqlBulkCopy is a Microsoft class that let you to efficiently bulk insert data to SQL Server table. That is the fastest way to insert multiples rows.
It's possible to improve SqlBulkCopy performance by specifying a batch size (not too low, not too high!) and locking the table using SqlBulkCopyOptions.
Here is a list of common SqlBulkCopy exceptions:
You cannot, but a third-party library does: Bulk Operations. It's a prime library that overcome SqlBulkCopy limitations.
Learn MoreYou cannot, but a third-party library does: Bulk Operations. It's a prime library that support all bulk operations:
It support SQL Server & SQL Azure. However more provide can be supported via Bulk Operations. It's a prime library that support all major providers: