zoukankan      html  css  js  c++  java
  • 用存储过程加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();
                //}

                return true;
            }

  • 相关阅读:
    Nginx部署部分https与部分http【转】
    MySQL指定使用某个索引查询语句
    MySQL创建相同表和数据命令
    Apache+jboss群集部署
    运维小知识之nginx---nginx配置Jboss集群负载均衡
    SSL证书生成方法【转】
    Nginx搭建https服务器
    基于OpenSSL实现C/S架构中的https会话
    OnlineJudgeServer运行
    百科知识 isz文件如何打开
  • 原文地址:https://www.cnblogs.com/wxf82610/p/2860697.html
Copyright © 2011-2022 走看看