Home > Database > Mysql Tutorial > body text

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

WBOY
Release: 2016-06-07 17:55:02
Original
1162 people have browsed it

用存储过程配合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();
/
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!