首页 > 代码库 > 循环写入Insert 与 SqlBulkcopy
循环写入Insert 与 SqlBulkcopy
/* Insert by Loop */ cmd.CommandText = "insert into BizSharedStore (BizSharedStoreId,BizSharedId,StoreCode,StartDt,EndDt) values (@BizSharedStoreId,@BizSharedId,@RuleCode);"; cmd.CommandType = CommandType.Text; foreach (var x in query_BizSharedList) { try { cmd.Parameters.Clear(); cmd.Parameters.Add("@BizSharedListId", SqlDbType.VarChar).Value =http://www.mamicode.com/ x.BizSharedListId.ToString(); cmd.Parameters.Add("@BizSharedId", SqlDbType.VarChar).Value =http://www.mamicode.com/ x.BizSharedId; cmd.Parameters.Add("@RuleCode", SqlDbType.VarChar).Value =http://www.mamicode.com/ x.Rulecode; cmd.ExecuteNonQuery(); } catch (Exception ex) { MessageBox.Show("Insert BizShardList Error:" + ex.Message); } } // End of Insert by Loop MessageBox.Show("insert into BizSharedList by Insert Loop, Successfully!");
SqlBulkcopy
using (SqlBulkCopy bulk1 = new SqlBulkCopy(conn)) { bulk1.DestinationTableName = "BizSharedList"; //bulk1.ColumnMappings.Add("BizSharedListId", "BizSharedListId"); //bulk1.ColumnMappings.Add("BizSharedId", "BizSharedId"); //bulk1.ColumnMappings.Add("RuleCode", "RuleCode"); bulk1.WriteToServer(tbl_BizSharedList); } MessageBox.Show("Bulk Insert Table: BizSharedList Successfully!");
循环写入Insert 与 SqlBulkcopy
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。