错误:无法通过行访问已删除的行信息 [英] Error: Deleted row information cannot be accessed through the row

查看:33
本文介绍了错误:无法通过行访问已删除的行信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这可能与谁有关,我已经搜索了大量时间,以解决此错误

To whom this may concern, I have searched a considerable amount of time, to work a way out of this error

无法通过行访问已删除的行信息"

"Deleted row information cannot be accessed through the row"

我知道一旦从数据表中删除了一行,就无法以典型方式访问它,这就是我收到此错误的原因.最大的问题是我不知道该怎么做才能得到我想要的结果,我将在下面概述.

I understand that once a row has been deleted from a datatable that it cannot be accessed in a typical fashion and this is why I am getting this error. The big issue is that I am not sure what to do to get my desired result, which I will outline below.

基本上,当dg1"中的一行被删除时,它下面的行会代替被删除的行(显然),从而继承被删除的行索引.此方法的目的是替换和重置行索引(通过从数据集中的相应值中获取),这些行索引占据了已删除行的位置,因此索引值.

Basically when a row in "dg1" is deleted the row beneath it takes the place of the deleted row (obviously) and thus inherits the deleted rows index. The purpose of this method is to replace and reset the rows index (via grabbing it from the corresponding value in the dataset) that took the deleted rows place and as such the index value.

现在我只是使用标签 (lblText) 来尝试从进程中获取响应,但是当最后一个嵌套的 if 语句尝试比较值时它崩溃了.

Right now I am just using a label (lblText) to try and get a response from the process, but it crashes when the last nested if statement trys to compare values.

代码如下:

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'
                }
            }
        }

提前感谢您的帮助,我确实进行了搜索,如果通过简单的谷歌搜索很容易找出答案,那么请允许自己反复讨厌我,因为我确实尝试过.

Thanks ahead of time for the help, I really did search, and if it is easy to figure out through a simple google search then allow myself to repeatably hate on me, because I DID try.

  • gc

推荐答案

内部 if 语句中数据列的当前值将不可用于已删除的行.要检索已删除行的值,请指定您需要原始值.这应该可以解决您的错误:

The current value for the data column in the inner if statement will not be available for deleted rows. To retrieve a value for deleted rows, specify that you want the original value. This should fix your error:

if (Convert.ToString(ds.Tables[0].Rows[i][0, DataRowVersion.Original].ToString()) == value)

这篇关于错误:无法通过行访问已删除的行信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆