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

2023年 4月 18日 29.8k 0

复制代码 代码如下: public bool SaveSMSMessage(SMSBatch smsBatch, DataSet smsMessages) { //using (TransactionScope ts = new TransactionScope(TransactionScopeOption.Suppress)) //{ foreach (DataRow row in smsMessages.Tables[0].Rows) ro

复制代码 代码如下: 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; }

相关文章

Oracle如何使用授予和撤销权限的语法和示例
Awesome Project: 探索 MatrixOrigin 云原生分布式数据库
下载丨66页PDF,云和恩墨技术通讯(2024年7月刊)
社区版oceanbase安装
Oracle 导出CSV工具-sqluldr2
ETL数据集成丨快速将MySQL数据迁移至Doris数据库

发布评论