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

  • 相关阅读:
    testNg vs junit 4.X @Test
    lombok+slf4j+logback SLF4J和Logback日志框架详解
    IntelliJ IDEA 当pom.xml更新时,自动加载pom.xml
    运算符重载具体解释
    设计模式之十八:桥接模式(Bridge)
    无限层级的组织机构
    实战Jquery(一)--username校验
    Android错误之--Error retrieving parent for item: No resource found that matches the given name 'Theme.A
    hibernate 缓存
    android --多线程下载
  • 原文地址:https://www.cnblogs.com/wxf82610/p/2860697.html
Copyright © 2011-2022 走看看