使用DataSet更新TableAdapter - Update需要有效的DeleteCommand错误

Ric*_*hGK 0 c# winforms

在下面的代码中,"在传递带有已删除行的DataRow集合时,Update需要有效的DeleteCommand".意思?

foreach (DataGridViewRow item in this.dataGridView2.SelectedRows)
{
    fuelStopsDataSet1.Tables[0].Rows[item.Index].Delete();
}

this.fuelStopsTableAdapter.Update(this.fuelStopsDataSet1.FuelStops);
Run Code Online (Sandbox Code Playgroud)

Kek*_*mau 5

您可以在某些情况下自动创建DeleteCommand(从SelectCommand推断).

SqlDataAdapter da = new SqlDataAdapter("...SELECT Statement...", connection);
SqlCommandBuilder cmd_b = new SqlCommandBuilder(da); // this already creates 
// the Update- and DeleteCommands for the DA
Run Code Online (Sandbox Code Playgroud)

这是一篇关于它的文章:http:
//msdn.microsoft.com/library/vstudio/tf579hcz.aspx