DatabaseService DBS = new DatabaseService();//这个是我自己定义的一个数据库服务类
        DataSet ds = DBS.Select_all("customer_information");//选择一个叫("customer_information")的表的所有内容
        string name = ds.Tables[0].Rows[0]["name"].ToString();//用Tables[0]就可以
        string pass = ds.Tables["customer_information"].Rows[0]["password"].ToString();//这里用表名就报错
----------------
下面是错误提示:
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.
我该怎么改一下,才能使用Tables["customer_information"]呢?
我原来都是用tables[0],看到别人用表名感觉比用数字好想改过来,碰到的问题。

解决方案 »

  1.   

    你用DataAdapter填充的时候就要把名字弄好,或是:
    ds.Tables[0].TableName = "XX";
    ds.Tables[1].TableName = "YY";
    ....如果你用监视去看一下Dataset的话,你会发现默认的表名是tables["TableX"],X:是个数字(不记得是基于0还是1了)
      

  2.   

    sqlad.Fill(ds, "Table_name")   
      

  3.   

    XXXDataAdapter adp.Fill(.......)
    有重载的参数有包含表名的,试下指定表名再试下要不这样
    ds.table[0].tableName="xxx";
    试下了
      

  4.   

    1.想用名字的话,楼主要自己给它起名
    就像3个人排在一起,你叫第一个,它知道,
    你叫XXX,它不知道,因为事先你没告诉它
    2.一个存储过程中有多个select的时候,返回到dataset的时候
    table的顺序和select的顺序是一致的tabel[0] 第一个select的结果
    tabel[1] 第二个select的结果
    ......