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

  • 相关阅读:
    java移位的具体应用
    mysql计划任务(轮询执行脚本)
    算法题(1)
    transient关键字及Serializable的序列化与反序列化
    java后台调用短信接口,实现发送短信验证码的控制层实现
    防卫导弹
    C++ STL
    字母转换
    三分·三分求极值
    各种数据类型取值范围
  • 原文地址:https://www.cnblogs.com/wxf82610/p/2860697.html
Copyright © 2011-2022 走看看