public int CalculateRecord()
    {
        int intCount;
        string strCount;        strCount = "select count(*) as co from fileup";
        SqlCommand MyComm = new SqlCommand(strCount, mycon);
        SqlDataReader dr = MyComm.ExecuteReader();
        if (dr.Read())
        {
            intCount = Int32.Parse(dr["co"].ToString());
        }
        else
        {
            intCount = 0;
        }
        dr.Close();
        return intCount;
    }

解决方案 »

  1.   


    public int CalculateRecord()
        {
            int intCount;
            string strCount;        strCount = "select count(*) as co from fileup";
            SqlCommand MyComm = new SqlCommand(strCount, mycon);
            mycon.Open();       //打开连接
            SqlDataReader dr = MyComm.ExecuteReader();
            if (dr.Read())
            {
                intCount = Int32.Parse(dr["co"].ToString());
            }
            else
            {
                intCount = 0;
            }
            dr.Close();
            mycon.Close();      //关闭连接 
            return intCount;
        }
      

  2.   

    mycon从哪里来的呀?
    首先生成SqlConnection,然后打开此连接。
      

  3.   


    SqlCommand MyComm = new SqlCommand(strCount, mycon);
    MyComm.Connection.Open();
    SqlDataReader dr = MyComm.ExecuteReader();
    if (dr.Read())
      

  4.   

    SqlConnection mycon=new SqlConnetion("连接字符串");
    mycon.Open();