标题:循环执行sql 语句,一起提交,多行的时候总是在等待状态,一行就没有问题
取消只看楼主
zsyutian
Rank: 1
等 级:新手上路
帖 子:48
专家分:0
注 册:2006-6-30
 问题点数:0 回复次数:0 
循环执行sql 语句,一起提交,多行的时候总是在等待状态,一行就没有问题
public static Boolean ExecuteQuery(string ConnectionSql, string[] ExeuteSql)//这里有个sql 语句string数组
      {
          Boolean Rtn=true;
          SqlConnection _SqlConn = new SqlConnection(ConnectionSql);
          _SqlConn.Open();
          SqlTransaction trans = _SqlConn.BeginTransaction();
          try
          {
              foreach (string sql in ExeuteSql)
              {
                  if (sql.Trim() != "")
                  {
                      ExecuteQueryEnd(_SqlConn, trans, sql);//执行下面的方法,到后面一起提交,防止出现有的提交有的不能提交的问题
                  }
                  else
                  {
                      continue;
                  }              
              }
              ();
          }
          catch (System.Data.SqlClient.SqlException e)
          {
              trans.Rollback();
              Rtn = false;
              throw new Exception(e.Message);
          }
          _SqlConn.Close();
          return Rtn;
        }
      public static  void ExecuteQueryEnd(SqlConnection conn, SqlTransaction str,string sqlcmd)
      {              
          SqlCommand _Scmd = new SqlCommand(sqlcmd,conn);   
          _Scmd.Transaction = str;
          _ = CommandType.Text;                    
          _ = 6000;
          try
          {
              _Scmd.ExecuteNonQuery();
          }
          catch
          {
              str.Rollback();
          }        }
搜索更多相关主题的帖子: sql insert 语句 string 状态 
2008-07-11 11:40



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-223485-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.182022 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved