System.Data.RowNotInTableException - Why?

S

Sasha

Hi everybody,



I am having the following problem. While running my program I create a
DataRow (State - Detached). Then I add it to the DataTable (State - Added),
and delete it (State - Detached). Later I try to update the db by doing this

DataAdapter.Update(DataTable.Select("", "", DataViewRowState.Added))

DataAdapter.Update(DataTable.Select("", "", DataViewRowState.Modified))

DataAdapter.Update(DataTable.Select("", "", DataViewRowState.Deleted))

When I try to update the deleted records I get the following message:



"This row has been removed from a table and does not have any data.
BeginEdit() will allow creation of new data in this row.
System.Data.RowNotInTableException"



Does anyone know why this happens?
 
R

Ravikanth[MVP]

Hi


Represents the exception that is thrown when trying to
perform an operation on a DataRow that is not in a
DataTable.


Ravikanth[MVP]
 
L

Laurent Lequenne

This means, that you created the row by another way then the "newrow() ?"
method of the datatable where you want to put the new row :)
 
S

Sasha

I understand this. But why is exception thrown?


Ravikanth said:
Hi


Represents the exception that is thrown when trying to
perform an operation on a DataRow that is not in a
DataTable.


Ravikanth[MVP]
 
J

Jacob Yang [MSFT]

Hi Sasha,

I am very glad to know that the problem is resolved.

Is it possible for you to share your solution? Our goal is to provide
information to the entire community and the newsgroups allow everyone else
to benefit from our conversations. Thank you for your understanding. I
certainly appreciate your time.

Best regards,

Jacob Yang
Microsoft Online Partner Support
<MCSD>
Get Secure! ¨C www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 
Joined
May 31, 2006
Messages
1
Reaction score
0
Solution

Wow, almost three years later, using VS2005 and Access 2003, i stumbled upon nearly the same problem. Funnily enough this problem only started after i converted my AutoNumber userID to a Manually populated ReplicationID.

The main problem in this exception is understanding what it ACTUALLY means. Yeah sure..everyone says 'it has been removed from the table' but what does that actaully mean?

In my case i got this error when i added a row. My method for doing this would be to populate a strongly typed row to a data handler class i wrote, which would in turn use the strongly typed dataset and datatables to insert the row into the table.

Now the actual insert itself worked, but the problem came in where i used that same datarow i used to pass to the datahandler, in the next line of code thereafter, i try to pass it to another method which populates form fields from a datarow. I couldnt understand why the insert worked, and i used the same row and it wouldnt work. (i got the exact same exception as mentioned in this thred). I eventually realised that the row that i used was in some way dissasociated from the dataset after i passed it and all i had to do was reload it with the values from the database. That resolved my issue.

Hope this helps others.
 
Joined
Feb 19, 2009
Messages
1
Reaction score
0
another 3 years later!
i am having a similar issue. except that my datarow is not a new row at all.
i insert the row into the database. then I pull it back out to get all the default values. I have a wrapper class that does some additional logic (like cross referencing foreign key fields) for this data row. when I try to access a property of this wrapper class which references the DataRow, i get this exception. see pseudo snippet below


function1()
{
adapter.InsertRow(primaryKey)
adapter.FillByPK(dataTable, primaryKey)

dsDataSet.SomeTableRow row = (dsDataSet.SomeTableRow)dataTable.Rows[0];

RowWrapper rw = new RowWrapper(row);

datagridview1.rows.add(rw.dataGridValues());
}

the member function dataGridValues() returns an object array with as many elements as there are columns in the data grid. in a hidden column it stores itself.
looks something like this

public object[] DataGridValues()
{
List<object> rv = new List<object>();
rv.Add(JONUM);
rv.Add(OPENDATE);
rv.Add(COMPDATE);
rv.Add(CREWDESC);
rv.Add(CATEGORYNAME);
rv.Add(TASKNAME);
rv.Add(this);
return rv.ToArray();
}

now in another function I need to get at the object again, not just the colums displayed in the grid.

so I do something like:

JobOrder jo = jobRequestsGrid.SelectedRows[0].Cells["JORAWDATA"].Value as JobOrder;
if (null == jo)
{
throw new NullReferenceException("Job Order Data is Corrupt");
}
activeJobOrder = jo;
currentJONUM = activeJobOrder.JONUM; // <----- Exception thrown here
BeginEditingSelectedRow();


when I try to access a property of the job order, I get this exception.

any ideas?

thanks
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top