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

  • 相关阅读:
    Wildcard Matching
    【Unity3D游戏开发】NGUI之DrawCall数量 (四)
    POJ1328 Radar Installation 【贪心·区间选点】
    [C/C++标准库]_[0基础]_[怎样实现std::string自己的Format(sprintf)函数]
    Android程序崩溃异常收集框架
    括号配对问题
    android dp 和 px 的相互转换
    freemarker写select组件报错总结(四)
    [redis]redis概述
    oracle数据库权限管理
  • 原文地址:https://www.cnblogs.com/wxf82610/p/2860697.html
Copyright © 2011-2022 走看看