Having problems deleting a row

C

Carl Mercier

Hi,

I'm trying to delete a row from a datatable at runtime but an exception is
thrown. I have no clue why since I'm not even using an iterator.

Here's my code:

' Search for deleted items at client side
For Each t As DataTable In dsWeb.Tables
For i As Integer = 0 To t.Rows.Count - 1
Dim dr As DataRow = t.Rows(i)
Dim foundRow As DataRow =
dsClient.Tables(t.TableName).Rows.Find(New Object() {dr(0), auth.User})

If foundRow Is Nothing Then
' this item was deleted
t.Rows(i).Delete() '<<<------- Exception thrown
here
Else
' Do nothing
End If
Next
Next

The exception is of type DeletedRowInaccessibleException (.Message = Deleted
row information cannot be accessed through the row).

I made sure that every row i was trying to delete is RowState = Unchanged.
I also tried many other ways of looping and deleting the rows but without
much success.

Can anyone help here?

Thanks!

Carl
 
M

Miha Markic

HI Carl,

Try reversing the loop
For i As Integer = t.Rows.Count - 1 to 0 step -1
 
M

Miha Markic

Hi Carl,

I've didn't read well your message.
Your problem might lie here:
dsClient.Tables(t.TableName).Rows.Find(New Object() {dr(0), auth.User})
You use dr(0) on deleted row.
 
C

Carl Mercier

Miha,

The problem is really on the .Delete line. I tried what you said anyway
but it did not help.

I'm lost :(

Carl
 
M

Miha Markic [MVP C#]

Hi Carl,

Since we are going in circles, you might send me a really simple sample if
you wish to.
 

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