我有一個數(shù)據(jù)表,需要將整個內(nèi)容推送到數(shù)據(jù)庫表。我可以使用foreach將所有內(nèi)容放入其中,并一次插入每一行。盡管由于有數(shù)千行,所以執(zhí)行速度非常慢。有什么方法可以一次完成整個數(shù)據(jù)表嗎?DataTable的列少于SQL表。其余的應(yīng)保留為NULL。
3 回答

BIG陽
TA貢獻1859條經(jīng)驗 獲得超6個贊
考慮這種方法,您不需要for循環(huán):
using (SqlBulkCopy bulkCopy = new SqlBulkCopy(connection))
{
bulkCopy.DestinationTableName =
"dbo.BulkCopyDemoMatchingColumns";
try
{
// Write from the source to the destination.
bulkCopy.WriteToServer(ExitingSqlTableName);
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
}
- 3 回答
- 0 關(guān)注
- 586 瀏覽
添加回答
舉報
0/150
提交
取消