public static DataTable getDataTable(string sqlStr)
        {
            OleDbConnection con = DBConnect();
            con.Open();
            OleDbCommand cmd = new OleDbCommand(sqlStr, con);
            OleDbDataAdapter sda = new OleDbDataAdapter();
            sda.SelectCommand = new OleDbCommand(sqlStr, con);
            OleDbCommandBuilder cmdBuilder = new OleDbCommandBuilder(sda);
            DataSet ds = new DataSet();
            sda.Fill(ds,"tables");
            con.Close();
            return ds.Tables["tables"];
        }        public static void bindGridView(DataGridView dataInfo, int selectIndex)
        {
            DataTable dt = getDataTable("select * from [FtpConfig]");
            dataInfo.DataSource = dt.DefaultView;//显示出错地方未将对象引用设置到对象的实例。
        }

解决方案 »

  1.   


    DataTable dt = getDataTable("select * from [FtpConfig]");单步调试 ,dt 是否为空.
      

  2.   

    dataInfo.DataSource = dt.DefaultView;//显示出错地方未将对象引用设置到对象的实例。
    可能dt==null
    是不是没查到啊
      

  3.   


    - dt {tables} System.Data.DataTable
      

  4.   

    试试dataInfo.DataSource = dt
      

  5.   

    public static void bindGridView(DataGridView dataInfo, int selectIndex)是不是传过来的参数dataInfo要实例化?
      

  6.   

    我是从另外一个含有DATAGRIDVIEW的页面,将其传过来的。
      

  7.   


    既然提示“未将对象引用设置到对象的实例”,就肯定是有Null值,楼主仔细调试一下,确定dt.DefaultView 的 dt肯定有值吗?