【发布时间】:2025-12-01 06:05:01
【问题描述】:
可能重复:
Error: Deleted row information cannot be accessed through the row. (C#)
当我尝试从我的 DataSet 中删除一行时出现此错误:
已删除的行信息无法通过行访问
我该如何解决这个问题。
下面是我的函数:
private void btnDelete_Click(object sender, EventArgs e)
{
var result = MessageBox.Show("Proceed to deleting this location?", "Delete Location", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
if (result == DialogResult.Yes)
{
var row = myData.xspArea.FindByxar_Id(pRow.xar_Id);
if (row.RowState != DataRowState.Deleted)
{
row.Delete();
MessageBox.Show("This location has been deleted", "Location Deleted", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
else
{
this.Close();
}
}
【问题讨论】:
-
我认为你需要在 row.Delete() 之后调用
mData.AcceptChanges()。 -
@YaqubAhmad:
AcceptChanges将阻止数据库中的更新,因为行状态是数据适配器用来确定如何处理行的内容。