存储过程配合UpdateDaset方法批量插入Dataset数据实现代码
程序员文章站
2023-11-24 09:35:52
复制代码 代码如下: public bool savesmsmessage(smsbatch smsbatch, dataset smsmessages) { //usin...
复制代码 代码如下:
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;
}