bAdapter.SelectCommand.CommandTimeout=600;
别忘了关闭连接,释放对象

解决方案 »

  1.   

    作成存储过程再调用
    ms-help://MS.VSCC.2003/MS.MSDNQTR.2003FEB.2052/cpguide/html/cpconusingstoredprocedureswithcommand.htm
    部分参考
    SqlConnection nwindConn = new SqlConnection("Data Source=localhost;Integrated Security=SSPI;Initial Catalog=northwind");SqlCommand salesCMD = new SqlCommand("SalesByCategory", nwindConn);
    salesCMD.CommandType = CommandType.StoredProcedure;SqlParameter myParm = salesCMD.Parameters.Add("@CategoryName", SqlDbType.NVarChar, 15);
    myParm.Value = "Beverages";nwindConn.Open();SqlDataReader myReader = salesCMD.ExecuteReader();Console.WriteLine("{0}, {1}", myReader.GetName(0), myReader.GetName(1));while (myReader.Read())
    {
      Console.WriteLine("{0}, ${1}", myReader.GetString(0), myReader.GetDecimal(1));
    }myReader.Close();
    nwindConn.Close();
      

  2.   

    我把它做成存储过程了,但不是不行,还是说超时下面是代码SqlConnection bConnection=new SqlConnection(strbConnection);
    bConnection.Open();
    SqlCommand bCommand=new SqlCommand();
    bCommand.Connection=bConnection;
    bCommand.CommandText="checkbrandgroupec";//存储过程名
    bCommand.CommandType=CommandType.StoredProcedure;
    SqlDataReader sdr=bCommand.ExecuteReader();
    DataTable cTable=new DataTable();
    cTable.Columns.Add("PC_BrnG",typeof(string));
    DataRow cdr;
    while(sdr.Read())
    {
    cdr=cTable.NewRow();
    cdr["PC_BrnG"]=sdr["PC_BrnG"];
    }
    //下面是存储过程,在查询分析器中是可以执行的,要2分50秒.
    CREATE PROCEDURE checkbrandgroupec
    AS
    SELECT t1.PC_BrnG,t1.PC_BrnN,t1.T_BrnG_E,t1.T_BrnG_C,t1.Sig,t1.re
    FROM table1 t1,table1 t2
    WHERE t1.PC_BrnG=t2.PC_BrnG
    AND (t1.T_BrnG_E<>t2.T_BrnG_E OR t1.T_BrnG_C<>t2.T_BrnG_C)
    GO