您现在的位置是:网站首页> 编程资料编程资料
存储过程配合UpdateDaset方法批量插入Dataset数据实现代码_MsSql_
2023-05-26
440人已围观
简介 存储过程配合UpdateDaset方法批量插入Dataset数据实现代码_MsSql_
复制代码 代码如下:
public bool SaveSMSMessage(SMSBatch smsBatch, DataSet smsMessages)
{
//using (TransactionScope ts = new TransactionScope(TransactionScopeOption.Suppress))
//{
foreach (DataRow row in smsMessages.Tables[0].Rows)
row.SetModified();
SqlDatabase db = new SqlDatabase(this.ConsultantsConnString);
string sqlCmd = "EXEC cn.SMSSaveSMSMessage @SMSBatchID, @SMSTypeID, @SubsidiaryID, @ContactID, @Message, @PhoneNumber";
using (SqlCommand cmd = db.GetSqlStringCommand(sqlCmd) as SqlCommand)
{
cmd.CommandTimeout = 600;
cmd.Parameters.AddWithValue("@SMSBatchID", smsBatch.SMSBatchID);
cmd.Parameters.AddWithValue("@SMSTypeID", smsBatch.SMSType.SMSTypeID);
cmd.Parameters.AddWithValue("@SubsidiaryID", smsBatch.SMSType.SubsidiaryID);
db.AddInParameter(cmd, "@ContactID", DbType.Int64, "ContactID", DataRowVersion.Current);
db.AddInParameter(cmd, "@Message", DbType.String, "Message", DataRowVersion.Current);
if (smsMessages.Tables[0].Columns.Contains("PhoneNumber"))
{
db.AddInParameter(cmd, "@PhoneNumber", DbType.String, "PhoneNumber", DataRowVersion.Current);
}
else
{
db.AddInParameter(cmd, "@PhoneNumber", DbType.String, DBNull.Value);
}
int rowsEffected = db.UpdateDataSet(smsMessages, "SMSMessage", null, cmd, null, UpdateBehavior.Transactional);
sqlCmd = rowsEffected.ToString();
}
// ts.Complete();
//}
return true;
}
您可能感兴趣的文章:
相关内容
- SQL里面用自定义Split()完成个性化需求_MsSql_
- Sql Server:多行合并成一行,并做分组统计的两个方法_MsSql_
- 将备份的SQLServer数据库转换为SQLite数据库操作方法_MsSql_
- SQLSERVER对索引的利用及非SARG运算符认识_MsSql_
- SQLSERVER记录登录用户的登录时间(自写脚本)_MsSql_
- SQLSERVER如何查看索引缺失及DMV使用介绍_MsSql_
- 诊断SQLSERVER问题常用的日志概述及使用_MsSql_
- 自动化收集SQLSERVER诊断信息的工具选择及使用介绍_MsSql_
- SQLSERVER聚集索引和主键(Primary Key)的误区认识_MsSql_
- SQLserver删除某数据库中所有表实现思路_MsSql_
