后台数据库为SQL2000
string connection1 = "Data Source=. ;Initial Catalog=图书馆;Integrated Security=True";
            SqlConnection con1 = new SqlConnection(connection1);
            con1.Open();
            DataSet dataSet = new DataSet("set1");
            string sql1 = "select * from Book";
            SqlDataAdapter a1 = new SqlDataAdapter(sql1, con1);
            a1.Fill(dataSet, "Book");
            DataColumn  [] keys = new  DataColumn [1];
            keys[0] = dataSet.Tables["Book"].Columns["图书号码"];
            dataSet.Tables["Book"].PrimaryKey = keys;
           
            SqlCommandBuilder scb1 = new SqlCommandBuilder(a1);
            
         a1.MissingSchemaAction = MissingSchemaAction.AddWithKey;
            dataSet.Tables["Book"].Rows.Find(" textBox7.Text").Delete();
            a1.Update(dataSet,"Book ");
运行后报错如下  
未处理 System.NullReferenceException
  Message="未将对象引用设置到对象的实例。"
  求解  问题出在哪里了?
这里小弟先谢过了!

解决方案 »

  1.   

     dataSet.Tables["Book"].Rows.Find(" textBox7.Text").Delete();
      dataSet.Tables["Book"].AcceptChanges;
     a1.Update(dataSet.Tables["Book"]);//又不是Fill,这个就错了
      

  2.   

    先谢谢这位朋友
    当我把dataSet.Tables["Book"].Rows.Find(" textBox7.Text").Delete();换成dataSet.Tables["Book"].Rows[0].Delete();的时候
    操作成功了 
    现在确定问题就出在这个Find() 身上了 
    但是不知道错在哪里了
      

  3.   

    var row = dataSet.Tables["Book"].Rows.Find(textBox7.Text);
    if(row != null)
    {
      row.Delete();
      a1.Update(dataSet,"Book ");
    }
    这里的Find查找匹配行,不一定能找到,因此不能直接对Find的返回值调用Delete方法,必须先做是否为空的判断。
      

  4.   

    茅塞顿开
    又犯了null.XX的错误了
    见笑了
    非常感谢