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;
            }

  • 相关阅读:
    JQuery判断CheckBox是否选中
    Ghost下的gho镜像分区工具
    JQuery提示$(...).on is not a function解决方法
    Jetty错误: badMessage: java.lang.IllegalStateException: too much data after closed for HttpChannelOverHttp@472adad9{r=2,c=false,a=IDLE,uri=}
    Linux下使用Shell过滤重复文本(转)
    JQuery给动态HTML绑定事件
    Chrome插件在页面上直接绑定JavaScript事件提示Refused to execute inline event handler because it violates the following Co
    解决——》java.lang.IllegalArgumentException: Body parameter 0 was null
    qhclass
    java类uuid源码分析
  • 原文地址:https://www.cnblogs.com/wxf82610/p/2860697.html
Copyright © 2011-2022 走看看