oConn 没有打开
你打开的是SqlConn.Open();

解决方案 »

  1.   

    需要打开的并且可用的连接。该连接的当前状态是 Closed。
    ==>提示相当明确
      

  2.   

    OleDbCommand oCommand = new OleDbCommand(sql,SqlConn);
      

  3.   

    OleDbConnection oConn = new OleDbConnection(strConn); 这一行去掉.多余的
      

  4.   

    按照楼上的方法做了
    但是出现编译错误:
    1.OleDbCommand oCommand = new OleDbCommand(sql,SqlConn)代码中的"new"
    与System.Data.OleDb.OleDbCommand.OleDbCommand(string,System.Data.OleDb.OleDbConnection)"最匹配的重载方法具有一些无效参数
    2.OleDbCommand oCommand = new OleDbCommand(sql,SqlConn)中的"SqlConn"无法从"System.Data.SqlClient.SqlConnection"转换为"System.Data.OleDb.OleDbConnection"
    这些又是什么意思啊?
      

  5.   

    OleDbConnection oConn = new OleDbConnection(strConn); 
    这句下面跟着你就要 oConn.Open();
      

  6.   

    string sql = "select count(*) as fintLoginCount from T_Operator where fchrAction='1'";
    string StrConn = "server =(local); uid = wangwei; password = 1234; database =db_netForum";
    SqlConnection SqlConn = new SqlConnection(StrConn);
    OleDbCommand oCommand = new OleDbCommand(sql,SqlConn);
    SqlConn.Open();
    OleDbDataReader oReader = oCommand.ExecuteReader();
    int intLoginCount = 0;
    while (oReader.Read())
    {
    intLoginCount = (int)oReader["fintLoginCount"];
    }
    oReader.Close();
    SqlConn.Close();
    return intLoginCount;
      

  7.   

    OleDbConnection oConn = new OleDbConnection(strConn); 这一行去掉.
    SqlConnection SqlConn = new SqlConnection(StrConn); 改为 
    OleDbConnection oConn = new OleDbConnection(strConn); 你不要又用oledb的又用sql的啊...net不是万能的
      

  8.   

    改错了,不好意思~~~
    string sql = "select count(*) as fintLoginCount from T_Operator where fchrAction='1'";
    string StrConn = "server =(local); uid = wangwei; password = 1234; database =db_netForum";
    SqlConnection SqlConn = new SqlConnection(StrConn);
    SqlCommand oCommand = new SqlCommand(sql,SqlConn);
    SqlConn.Open();
    SqlDataReader oReader = oCommand.ExecuteReader();
    int intLoginCount = 0;
    while (oReader.Read())
    {
    intLoginCount = (int)oReader["fintLoginCount"];
    }
    oReader.Close();
    SqlConn.Close();
    return intLoginCount;
      

  9.   

    string sql = "select count(*) as fintLoginCount from T_Operator where fchrAction='1'";
    string StrConn = "server =(local); uid = wangwei; password = 1234; database =db_netForum";
    SqlConnection SqlConn = new SqlConnection(StrConn);
    SqlConn.Open();
    SqlCommand oCommand = new SqlCommand(sql,SqlConn);

    SqlDataReader oReader = oCommand.ExecuteReader();
    int intLoginCount = 0;
    while (oReader.Read())
    {
    intLoginCount = (int)oReader["fintLoginCount"];
    }
    oReader.Close();
    SqlConn.Close();
    return intLoginCount;
      

  10.   

    OleDbCommand oCommand = new OleDbCommand(sql,oConn);
    SqlConn.Open();<<<<--改成oConn.Open();就好了
      

  11.   

    我改了后又出现
    未将对象引用设置到对象的实例。 
    说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。 异常详细信息: System.NullReferenceException: 未将对象引用设置到对象的实例。源错误: 
    行 76: string ErrDesc = "";
    行 77: DataSet oDataSet = oForum.getForumList(CONNSTRING,out ErrDesc);
    行 78: dgrForumList.DataSource = oDataSet.Tables["T_Function"].DefaultView;
    行 79: dgrForumList.DataBind();
    行 80:  }源文件: C:\Inetpub\wwwroot\sampelForum\InitList.aspx.cs    行: 78 
    堆栈跟踪: 
    [NullReferenceException: 未将对象引用设置到对象的实例。]
       SampleForum.forumList.InitList() in C:\Inetpub\wwwroot\sampelForum\InitList.aspx.cs:78
       SampleForum.forumList.Page_Load(Object sender, EventArgs e) in C:\Inetpub\wwwroot\sampelForum\InitList.aspx.cs:50
       System.Web.UI.Control.OnLoad(EventArgs e)
       System.Web.UI.Control.LoadRecursive()
       System.Web.UI.Page.ProcessRequestMain()
    这段代码是这样的
    public void InitList()
    {
    dgrForumList.PageSize =10;
    dgrForumList.PagerStyle.Mode=PagerMode.NumericPages;
    ForumC oForum = new ForumC();
    string ErrDesc = "";
    DataSet oDataSet = oForum.getForumList(CONNSTRING,out ErrDesc);
    dgrForumList.DataSource = oDataSet.Tables["T_Function"].DefaultView;
    dgrForumList.DataBind();
    }
    string gstrSortOrder;
    public void SortRows(Object objSender,DataGridSortCommandEventArgs objArgs)
    {
    //当表头点击事件时调用
    gstrSortOrder = objArgs.SortExpression.ToString();
    }
    这边又要怎么改啊~~??
     
      

  12.   

    //方法名惯例大写开头,写成GetUserCount更合理
    public int getUserCount(string strConn)
    {
    string sql = "select count(*) as fintLoginCount from T_Operator where fchrAction='1'";
    OleDbConnection oConn = new OleDbConnection(strConn); 
    //上面有个小写的参数strConn,现在又声明一个大写的StrConn,你究竟想做what?很容易混乱的
    string StrConn = "server =(local); uid = wangwei; password = 1234; database =db_netForum";SqlConnection SqlConn = new SqlConnection(StrConn);
    OleDbCommand oCommand = new OleDbCommand(sql,oConn);
    //你的SqlConn打开了 oConn就不管了?
    SqlConn.Open();
    //oConn没打开 oReader里面肯定没东西啊
    OleDbDataReader oReader = oCommand.ExecuteReader();
    int intLoginCount = 0;
    while (oReader.Read())
    {
    intLoginCount = (int)oReader["fintLoginCount"];
    }
    oReader.Close();
    SqlConn.Close();
    return intLoginCount;
    }最后,楼主,你自己想清楚究竟该打开那个连接了吗?