Deleted row in dataset??

  • Thread starter Joris De Groote
  • Start date
J

Joris De Groote

Hi,

(my code is @ the bottom of this message)

I have a piece of code that runs the rows of a dataset until it finds the
one needed. When he finds it, I delete that row and start all over again
with the next row I'm looking for, however. I then get this error:
System.Data.DeletedRowInaccessibleException: Deleted row information cannot
be accessed through the row.

The problem seems to be that the dataset deletes the information of the row,
but still keeps the row in it? Now I want to get rid of that one row so my
next run could potentionaly go faster since it has to go over one record
less each time this runs (when the record is below the one that is deleted
offcourse).

Thanks
Joris


While (vi < ds.Tables("vrachtbrieven").Rows.Count)
If (Not
(ds.Tables("docs").Rows(di).Item(0).ToString.Equals(ds.Tables("vrachtbrieven").Rows(vi).Item(0).ToString)))
Then
erin = False
Else
erin = True
ds.Tables("vrachtbrieven").Rows(vi).Delete()
vi = ds.Tables("vrachtbrieven").Rows.Count
End If
vi += 1
End While
 
C

Cor Ligthert [MVP]

Joris,

Deleting of rows is slow, as well be aware that there is a difference
between deleting and removing.
Deleting keeps in some situations the row to make updates to a database
possible
Removing removes the row totally and therefore update is impossible.

But for deleting or removing you can better do a job bottom up with a for
loop

\\\Typed in this message so see it as a kind of pseudo code
For each dr in ds.tables("vrachtbrieven").rows
For i as integer = ds.Tables("docs").Rows.count - 1 to 0 step -1
if
(ds.Tables("docs").Rows(i).Item(0).ToString.Equals(ds.Tables("vrachtbrieven").Rows(i).Item
(0).ToString))) then ds.Tables("docs")Rows(i).Delete
Next
Next
///

I hope this helps,

Cor
 
J

Joris De Groote

Hi Cor,
thanks for you reply. The situation is that I have 2 tables, one in a
dataset that I go through and another in a dataset wich I go trough every
record of the first table (or until the matching record has been found). Now
this takes quite some time and everyday table 1 gets 2000-3000 extra records
and table 2 1000 extra records, so every day it gets slower. Now I'm looking
for some ways to speed this up and I was thinking that with deleting a
record I could speed it up a bit but since I get this error, it's not that
great sollution it seems.
Could you mayby give some other sollutions on how to speed things up? Would
a select from sql database be faster?

Thanks
Joris
 
C

Cor Ligthert [MVP]

Joris,

Did you try my sample?

(The inner for loop can be exited of course with an Exit For and than the
then becomes an then with an end if.)

I assume that in fact every day this has to be done completely, althoug as I
understand you well, than you can use in the outerloop use instead of the
complete table only the additions for this day, which you probably can get
with a where clause.

Cor
 
J

Joris De Groote

Hi,

Thanks for your response. I have used your advice with the where clause and
this could help me quite a bit :). Why didn't I come up with this...

Joris
 

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

Similar Threads


Top