如何激发lostrowinaccessibleexception [英] How to provoke deletedrowinaccessibleexception

查看:101
本文介绍了如何激发lostrowinaccessibleexception的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





任何人都可以提供一个抛出的样本 DeletedRowInaccessibleException n?



背景:

我有找出一个不可重现的错误(我不是数据表中的大专家)。在我的生产代码中,我曾在大型代码块中的某处获得DeletedRowInaccessibleException(我不知道行号,因为我们不提供pdb文件)。所以我的第一个方法是找到一个产生异常的样本(我目前已经失败了)。到目前为止我只能 RowNotInTableException



使用.net 4.6.2



非常感谢提前



我的尝试:



Hi,

Can anyone provide a sample that throws DeletedRowInaccessibleExceptionn?

Background:
I have to find out about a non reproducible error (and I'm not a big expert in datatables). In my production code I once got DeletedRowInaccessibleException somewhere in a large codeblock (and I don't know the line number as we do not provide pdb files). So my first approach is to find a sample that produces the exception (with which I currently fail already). All I get so far is RowNotInTableException

Am using .net 4.6.2

Many thanks in advance

What I have tried:

void test()
        {
            DataTable dt = new DataTable();
            dt.Columns.Add("col1", typeof(string));
            dt.Columns.Add("col2", typeof(long));
            DataRow dr1 = dt.NewRow();
            dt.Rows.Add(dr1);
            dr1.ItemArray = new object[] { "a", 123L };
            DataRow dr2 = dt.NewRow();
            dt.Rows.Add(dr2);
            dr2.ItemArray = new object[] { "b", 456L };
            dr1.Delete();
            Console.WriteLine("value 1/1: {0}", dr1.ItemArray[0]); //<-- throws RowNotInTableException. What do I need to do to get DeletedRowInaccessibleException?
        }

推荐答案

当你获得此异常您正尝试从类型化数据集中访问已删除的行



You will get this exception, when you are trying to access the deleted row from a Typed Dataset

Quote:

我需要做什么才能获得DeletedRowInaccessibleException?

What do I need to do to get DeletedRowInaccessibleException?





右键单击项目 - >添加 - >新商品 - >数据 - >数据集 - >在设计器窗口中将其命名为 DataSet1.xsd

- >右键单击 - >添加 - > DataTable - >将其命名为 DataTable1 - >右键单击表格的标题并 - >添加 - > 2列(将其命名为 Column1 Column2 ) - > 保存



现在执行此代码





Right Click the project -> Add -> New Item -> Data -> DataSet -> Name it as DataSet1.xsd
in the designer window -> right click -> add -> DataTable -> Name it as DataTable1 -> right click the header of the table and -> add -> 2 Columns ( name it as Column1 and Column2 ) -> Save

now execute this code

static void Main(string[] args)
        {
            try
            {
                DataSet1 ds = new DataSet1();
                ds.DataTable1.AddDataTable1Row("1", "One");
                ds.DataTable1.AddDataTable1Row("2", "Two");
                ds.AcceptChanges();
                ds.DataTable1.Rows[0].Delete();
                foreach (DataSet1.DataTable1Row row in ds.DataTable1.Rows)
                {
                    string temp = row.Column1;
                } 

            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                 
            }
 
        }


这篇关于如何激发lostrowinaccessibleexception的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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