存储过程配合UpdateDaset方法批量插入Dataset数据实现代码

前端之家收集整理的这篇文章主要介绍了存储过程配合UpdateDaset方法批量插入Dataset数据实现代码前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

<div class="codetitle"><a style="CURSOR: pointer" data="85270" class="copybut" id="copybut85270" onclick="doCopy('code85270')"> 代码如下:

<div class="codebody" id="code85270">
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","PhoneNumber",DataRowVersion.Current);
}
else
{
db.AddInParameter(cmd,DBNull.Value);
}
int rowsEffected = db.UpdateDataSet(smsMessages,"SMSMessage",null,cmd,UpdateBehavior.Transactional);
sqlCmd = rowsEffected.ToString();
}
// ts.Complete();
//}
return true;
}

原文链接:https://www.f2er.com/mssql/63597.html

猜你在找的MsSQL相关文章