scdb_conn.Open();
SqlCommand scdb_comm = new SqlCommand(sql, scdb_conn);
SqlDataReader zbdh_reader = scdb_comm.ExecuteReader();
while (zbdh_reader.Read()
{
      zbdh = zbdh_reader[0].ToString();
      cc_conn.Open();
      //同一下数据库但是表不一样,查询sql也不一样,
      SqlCommand cc_comm = new SqlCommand(sql, scdb_conn);
      SqlDataReader cc = cc_comm.ExecuteReader();
      //为什么只运行到这就不运行了?
      //是不是READder里不是能再reader.Read()
      while(cc.reader.Read())
      {
       }}

解决方案 »

  1.   

    可以的,但是必须是2个连接对象。
    scdb_conn2.Open();SqlCommand cc_comm = new SqlCommand(sql, scdb_conn2);不能使用同一个连接
      

  2.   

    SqlDataReader 要先关闭,再执行ExecuteNonQuery操作
    using (SqlConnection cn = new SqlConnection(“”))
      {
      SqlCommand cmd1 = new SqlCommand("", cn);
      cn.Open();
      using (SqlDataReader dr1 = cmd1.ExecuteReader())
      {
      while (dr1.Read())
      {
      string sql= "";
      SqlConnection conn2 = new SqlConnection("");
      SqlCommand cmd2 = new SqlCommand(sql, conn2 );
      cmd2.ExecuteNonQuery();
      }
      }  }
      

  3.   

    sqlDataReader独占连接,某条连接上有sqldatareader的话,该连接无法为其他数据库访问对象所用,直到该sqlDataReader关闭
    SqlConnection scdb_conn = new SqlConnection("server...sa");
    SqlConnection scdb_conn2 = new SqlConnection("server...sa");
    ...
    SqlCommand scdb_comm = new SqlCommand(sql, scdb_conn);
    ...
    SqlCommand cc_comm = new SqlCommand(sql, scdb_conn2);