这可能与谁有关,我已经搜索了相当多的时间,以找到解决此错误的方法
"Deleted row information cannot be accessed through the row"
我知道一旦从数据表中删除了一行,就无法以典型方式访问它,这就是我收到此错误的原因。最大的问题是我不确定该怎么做才能获得我想要的结果,我将在下面概述。
基本上,当“dg1”中的一行被删除时,它下面的行将取代已删除的行(很明显),因此继承了已删除的行索引。此方法的目的是替换和重置代替已删除行的行索引(通过从数据集中的相应值中获取它)以及索引值。
现在我只是使用一个标签 (lblText) 来尝试从进程中获取响应,但是当最后一个嵌套的 if 语句尝试比较值时它崩溃了。
代码如下:
void dg1_Click(object sender, EventArgs e)
{
rowIndex = dg1.CurrentRow.Index; //gets the current rows
string value = Convert.ToString(dg1.Rows[rowIndex].Cells[0].Value);
if (ds.Tables[0].Rows[rowIndex].RowState.ToString() == "Deleted")
{
for (int i = 0; i < dg1.Rows.Count; i++)
{
if (Convert.ToString(ds.Tables[0].Rows[i][0].ToString()) == value)
// ^ **where the error is occurring**
{
lblTest.Text = "Aha!";
//when working, will place index of compared dataset value into rowState, which is displaying the current index of the row I am focussed on in 'dg1'
}
}
}
提前感谢您的帮助,我确实进行了搜索,如果通过简单的谷歌搜索很容易找出答案,那么请让我自己反复讨厌我,因为我确实尝试过。
- gc
最佳答案
您还可以使用 DataSet AcceptChanges() 方法来应用已删除的完整内容。
ds.Tables[0].Rows[0].Delete();
ds.AcceptChanges();
关于c# - 错误 : Deleted row information cannot be accessed through the row,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4321840/