代码:不知道错在那儿
private void button3_Click(object sender, EventArgs e)
{
SqlConnection Sqlcon = new SqlConnection(connection);
SqlDataAdapter Sda = new SqlDataAdapter( "select * from ts ",Sqlcon);
DataSet Ds= new DataSet();
//这一行通不过
//提示错误为:
未将对象引用设置到对象的实例。
Ds.Tables[ "ts "].Rows[0].Delete();
Sda.Update(Ds);
}
------解决方案--------------------Ds 里面没数据当然报错
------解决方案--------------------Sda.Fill(Ds, "ts ");
------解决方案--------------------不指定表名的话
Sda.Fill(Ds);
Ds.Tables[0].Rows[0].Delete();
------解决方案--------------------private void button3_Click(object sender, EventArgs e)
{
SqlConnection Sqlcon = new SqlConnection(connection);
SqlDataAdapter Sda = new SqlDataAdapter( "select * from ts ",Sqlcon);
SqlCommandBuilder cmb = new SqlCommandBuilder(Sda);//加这句
Sda.DeleteCommand = cmb.GetDeleteCommand();//加这句
DataSet Ds= new DataSet();
Sda.Fill(Ds, "ts ");
Ds.Tables[0].Rows[0].Delete();
错误: //当传递具有已删除行的 DataRow 集合时,更新要求有效的 DeleteCommand。
Sda.Update(Ds, "ts ");
}