private void BindData()
    { 
            string cmdText = "select * from RX_TABLE1 ORDER BY Staff_ID";
            SqlConnection myConnection = new SqlConnection(connectionString);
            SqlCommand myCommand = new SqlCommand(cmdText, myConnection);
            myConnection.Open();
            OscarDataReader dr = myCommand.ExecuteReader();
            StaffList1.DataSource =  dr;            StaffList1.DataBind();
       
           
          
            dr.Close();
            myConnection.Close();
       
       
    }StaffList1.DataBind();这里抛异常,未将对象引用设置到对象的实例...不知道怎么错了 小弟初学 请教 谢谢大家

解决方案 »

  1.   

    OscarDataReader dr?
      

  2.   

    StaffList1.DataSource 的数据源 不能是dr  要ds  dt之类的 dr 不是容器!
      

  3.   

      你用的什么数据库 
    换SqlDataReader 试试
      

  4.   

    是datasource 错了 ,datasource应该是 你的 数据源,你把datareader 拿给数据源做什么呢?
      

  5.   

    啊 对对 我写错了 那个private void BindData() 
        { 
                string cmdText = "select * from RX_TABLE1 ORDER BY Staff_ID"; 
                SqlConnection myConnection = new SqlConnection(connectionString); 
                SqlCommand myCommand = new SqlCommand(cmdText, myConnection); 
                myConnection.Open(); 
                SqlDataReader dr = myCommand.ExecuteReader(); 
                StaffList1.DataSource =  dr;             StaffList1.DataBind(); 
          
              
              
                dr.Close(); 
                myConnection.Close(); 
          
          
        } StaffList1.DataBind();这里抛异常,未将对象引用设置到对象的实例...问题还是这样子的
      

  6.   

    datareader 不能成为数据源么 它不是一个连接的向前的只读的数据流麽. 这个也是照书上看的 ..我新手 谢谢继续指点
      

  7.   


    http://www.cnblogs.com/chairongzhen/articles/1089850.html
      

  8.   

    OscarDataReader ?不清楚这是什么
      

  9.   

    老大;
    SqlDataReader dr = myCommand.ExecuteReader(); //你在这里设置断点看一下,你的dr中是什么
    StaffList1.DataSource =  dr; StaffList1.DataBind(); 
      

  10.   

    StaffList1.DataSource 的数据源 不能是dr  可以是dt         这个我理解
    可要是ds的话怎么用呢,ds不是一个表要怎么用呢
    可以解答一下吗