存儲過程配合UpdateDaset方法批量插入Dataset數(shù)據(jù)實現(xiàn)代碼
更新時間:2013年02月24日 14:33:02 作者:
用存儲過程配合UpdateDaset方法批量插入Dataset數(shù)據(jù),感興趣的你可不要錯過了哈,希望本文提供知識點可以幫助到你
復(fù)制代碼 代碼如下:
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;
}
相關(guān)文章
SQL中字段自增(IDENTITY,序列Sequence)的兩種方法
本文主要介紹了SQL中字段自增,主要包括IDENTITY,序列Sequence的兩種方法,具有一定的參考價值,感興趣的可以了解一下2023-11-11SQL學(xué)習(xí)筆記二 創(chuàng)建表、插入數(shù)據(jù)的語句
SQL學(xué)習(xí)筆記二 創(chuàng)建表、插入數(shù)據(jù)的語句,需要的朋友可以參考下。2011-08-08navicat導(dǎo)入sql數(shù)據(jù)庫文件的簡單實現(xiàn)
在很多項目當中都有sql文件導(dǎo)入到MySQL數(shù)據(jù)庫的需要,因為有sql數(shù)據(jù)庫文件,這個項目才能正常運行起來,本文主要介紹了navicat導(dǎo)入sql數(shù)據(jù)庫文件的簡單實現(xiàn),具有一定的參考價值,感興趣的可以了解一下2023-11-11