dbOperation operation=new dbOperation();//实例化数据库操作类dbOperation 对象
public bool readData()

    Conn.Open();//打开数据库连接
    string strSQL="select ID,UserName,PassWord from tb_user";//SQL语句
    operation.GetDataSet(strSQL,"tb_user");//读取数据,返回的是一个数据集dataSet
    return operation.dataSet;返回的是一个数据集dataSet

public bool GetUser(string userName,string passWord)
{
    DataRow row=operation.dataSet.Tables["tb_user"].NewRow();//添加新行    row["UserName"]=userName;
    row["PassWord"]=password;
    row["ID"]=AutoId("tb_user","ID");//调用AutoId的方法,添加自动生成的编号    operation.dataSet.Tables["tb_user"].Rows.Add(row);
    return true;
}public string AutoId(string tempTable,string userID);
{
    string strSQL="select max("+userID+") from "+tempTable+"";//SQL语句
    SqlDataReader reader=operation.Reader(strSQL);//调用方法Reader,返回一个SqlDataReader对象    //自动生成最大编号
    if(reader.HasRows())
    {
       reader.Read();
       int Num=0;
       Num=Convert.ToInt32(reader[0].ToString());       
       ++Num;
       string NewNo=String.Format("{0:0000}",Num);
       return NewNo;
    }
    else
    {
       return "0001"    
    }
}我用上面的方法网dataSet中添加新行,但是报错了,说是“未将对象引用到对象的实例”,但是我先把operation.dataSet赋值给另一个DataSet ds=new DataSet(),就能够添加新行成功。我不明白这到底是为什么,这两个数据集的数据不都是一样的吗?我修改后的程序是:dbOperation operation=new dbOperation();//实例化数据库操作类dbOperation 对象
public bool readData()

    Conn.Open();//打开数据库连接
    string strSQL="select ID,UserName,PassWord from tb_user";//SQL语句
    operation.GetDataSet(strSQL,"tb_user");//读取数据,返回的是一个数据集dataSet
    return operation.dataSet;返回的是一个数据集dataSet
}public bool GetUser(string userName,string passWord)
{
    DataSet ds=new DataSet();
    ds=operation.dataSet;//赋值给另一个数据集dataSet    DataRow row=ds.Tables["tb_user"].NewRow();//添加新行    row["UserName"]=userName;
    row["PassWord"]=password;
    row["ID"]=AutoId("tb_user","ID");//调用AutoId的方法,添加自动生成的编号    ds.Tables["tb_user"].Rows.Add(row);
    return true;
}public string AutoId(string tempTable,string userID);
{
    string strSQL="select max("+userID+") from "+tempTable+"";//SQL语句
    SqlDataReader reader=operation.Reader(strSQL);//调用方法Reader,返回一个SqlDataReader对象    //自动生成最大编号
    if(reader.HasRows())
    {
       reader.Read();
       int Num=0;
       Num=Convert.ToInt32(reader[0].ToString());       
       ++Num;
       string NewNo=String.Format("{0:0000}",Num);
       return NewNo;
    }
    else
    {
       return "0001"    
    }
}
我这样子修改了,然后就能添加成功了,我不明白operation.dataSet跟
DataSet ds=new DataSet();
ds=operation.dataSet;
这两个数据集到底有什么不同,希望有人能提点一下我,这到底是为什么,谢谢!