i have created a datatable dynamically from a text file .Now i need to store the values in database.i found some example using foreach and data row and it works fine
foreach (DataRow row in dt.Rows)
{
// insert statement
}
My doubt is that the data table may contain thousands of row, is it efficient to use a foreach loop or should i go for someother techniques like bulk copy(i have no idea about it so do help me).Thank you
If you’re using SQL Server, you should use the SqlBulkCopy class.
I converted from a loop like you described to using this class on a large set of data in one of my apps, and the performance boost was unbelievable.