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

2019/6/30 17:14:52

本文主要是介绍存储过程配合UpdateDaset方法批量插入Dataset数据实现代码,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

复制代码 代码如下:

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


这篇关于存储过程配合UpdateDaset方法批量插入Dataset数据实现代码的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!


扫一扫关注最新编程教程