码迷,mamicode.com
首页 > 数据库 > 详细

批量处理数据 SqlBulkCopy

时间:2014-09-27 12:37:49      阅读:192      评论:0      收藏:0      [点我收藏+]

标签:des   blog   http   io   os   使用   ar   数据   sp   

 

  string connectionString = new PublicDBHelper().GetCon(System.Configuration.ConfigurationManager.AppSettings["constring"].ToString());

using (SqlConnection destinationConnection = new SqlConnection(connectionString))
{
destinationConnection.Open();

using (SqlBulkCopy bulkCopy = new SqlBulkCopy(connectionString, SqlBulkCopyOptions.CheckConstraints | SqlBulkCopyOptions.FireTriggers))
{
try
{
bulkCopy.DestinationTableName = "TB_CusorderDetail";//要插入的表的表明
bulkCopy.ColumnMappings.Add("billno", "billno");//映射字段名 DataTable列名 ,数据库 对应的列名
bulkCopy.ColumnMappings.Add("billid", "billid");
bulkCopy.ColumnMappings.Add("spbm", "spbm");
bulkCopy.ColumnMappings.Add("spmc", "spmc");
bulkCopy.ColumnMappings.Add("spPrice", "spPrice");
bulkCopy.ColumnMappings.Add("spid", "spid");
bulkCopy.ColumnMappings.Add("splb", "splb");
bulkCopy.ColumnMappings.Add("splbid", "splbid");
bulkCopy.ColumnMappings.Add("sppp", "sppp");
bulkCopy.ColumnMappings.Add("spppid", "spppid");
bulkCopy.ColumnMappings.Add("ordernum", "ordernum");
bulkCopy.ColumnMappings.Add("orderPrice", "orderPrice");
bulkCopy.ColumnMappings.Add("issptz", "issptz");
bulkCopy.ColumnMappings.Add("remark", "remark");
bulkCopy.WriteToServer(tblDataDetails);
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
finally
{
// Close the SqlDataReader. The SqlBulkCopy
// object is automatically closed at the end
// of the using block.
}
}
}

实际使用过了,效果不太太好太明显

转自http://www.cnblogs.com/shikyoh/archive/2011/07/01/2095633.html

批量处理数据 SqlBulkCopy

标签:des   blog   http   io   os   使用   ar   数据   sp   

原文地址:http://www.cnblogs.com/panshengqiang/p/3996099.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!