数据库批量更新

2022/4/6 19:21:02

本文主要是介绍数据库批量更新,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

using (SqlConnection conn = (SqlConnection)_Database.CreateConnection())
{
SqlBulkCopy bulkCopy = new SqlBulkCopy(conn);
bulkCopy.DestinationTableName = "MY_SP_WorkProductConfig";
bulkCopy.ColumnMappings.Add("FID", "FID");
bulkCopy.ColumnMappings.Add("FFactoryCode", "FFactoryCode");
bulkCopy.ColumnMappings.Add("FProductCode", "FProductCode");
bulkCopy.ColumnMappings.Add("FProductName", "FProductName");
bulkCopy.ColumnMappings.Add("FDelete", "FDelete");
bulkCopy.ColumnMappings.Add("FMaker", "FMaker");
bulkCopy.ColumnMappings.Add("pig_form_id", "pig_form_id");
bulkCopy.ColumnMappings.Add("FPipeline", "FPipeline");

bulkCopy.BatchSize = dttable.Rows.Count;
if (conn.State == ConnectionState.Closed)
{
conn.Open();
}
if (dttable != null && dttable.Rows.Count != 0)
{
bulkCopy.WriteToServer(dttable);
}
conn.Close();
conn.Dispose();
}



这篇关于数据库批量更新的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!


扫一扫关注最新编程教程