欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

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

程序员文章站 2023-12-11 08:46:40
复制代码 代码如下: 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;
}