数据库
首页 > 数据库> > 数据库批量更新

数据库批量更新

作者:互联网

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();
}

标签:ColumnMappings,bulkCopy,批量,数据库,更新,pig,Add,dttable,conn
来源: https://www.cnblogs.com/yichen89/p/16105761.html