Click here to Skip to main content
15,889,877 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
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:

C#
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?
        }
Posted
Updated 14-Feb-17 23:05pm

1 solution

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

Quote:
What do I need to do to get DeletedRowInaccessibleException?


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

C#
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);
                 
            }
 
        }
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900