从数据表访问已删除的行 [英] Accessing deleted rows from a DataTable

查看:119
本文介绍了从数据表访问已删除的行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个家长的WinForm具有MyDataTable _dt 为成员。该MyDataTable类型是在类型数据集设计工具在Visual Studio 2005(MyDataTable从数据表继承)创建 _dt 会从通过ADO.NET分贝填充。基于表单的用户交互变化,我从表中删除一行,像这样:

I have a parent WinForm that has a MyDataTable _dt as a member. The MyDataTable type was created in the "typed dataset" designer tool in Visual Studio 2005 (MyDataTable inherits from DataTable) _dt gets populated from a db via ADO.NET. Based on changes from user interaction in the form, I delete a row from the table like so:

_dt.FindBySomeKey(_someKey).Delete();

后来, _dt 按值传递到对话框的形式。从那里,我需要通过所有的行扫描,以建立一个字符串:

Later on, _dt is passed by value to a dialog form. From there, I need to scan through all the rows to build a string:

           foreach (myDataTableRow row in _dt)
            {
                sbFilter.Append("'" + row.info + "',");
            }

问题是,在后删除这样做,下面的异常被抛出: DeletedRowInaccessibleException:已删除行的信息无法通过行访问

The problem is that upon doing this after a delete, the following exception is thrown: DeletedRowInaccessibleException: Deleted row information cannot be accessed through the row.

围绕我目前使用(这感觉就像一个黑客)的工作如下:

The work around that I am currently using (which feels like a hack) is the following:

           foreach (myDataTableRow  row in _dt)
            {
                if (row.RowState != DataRowState.Deleted &&
                    row.RowState != DataRowState.Detached)
                {
                    sbFilter.Append("'" + row.info + "',");
                }
            }

我的问题:这是正确的方式做到这一点?为什么会已通过了删除()方法??

推荐答案

您必须检查:

 _dt.DefaultView.RowStateFilter

我觉得默认的设置将不显示已删除的行,也许你的地方改变它。

I think that the default setting won't show deleted rows, maybe you change it somewhere.

您可以随时创建一个额外的RowView并控制其过滤器,做你的遍历视图。

You can always create an extra RowView and control its filter and do your loop over the View.

这篇关于从数据表访问已删除的行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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