有效的方式来存储数据表大到数据库中 [英] efficient way to store large datatable into database
问题描述
我创建从一个文本文件动态数据表。现在我需要存储在database.i发现使用的foreach和数据行的一些示例值和正常工作
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
}
我的疑问是,数据表可能包含成千上万行的,它是有效地使用foreach循环或者我应该去像批量复制someother技术(我有没有关于它的想法所以请帮助我)。谢谢
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
推荐答案
如果您正在使用SQL Server,则应该使用 SqlBulkCopy的类。
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.
这篇关于有效的方式来存储数据表大到数据库中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!