Q: Deleting rows in a DataView

  • Thread starter Thread starter Geoff
  • Start date Start date
G

Geoff

Hi

I'm hoping somebody can help me with the following.

I'm trying to delete all the rows in a dataview. There are 200 rows.
Everything works fine until I delete half way through and then I'm told in
an exception that

"There is no row at position 100"

The code I'm using is:

For Each i As Integer In MyList
dview.Delete(i)
Next

where MyList holds the numbers 0 to 199

There are 200 rows in the dataview (I can see them in a datagrid).

Can anybody tell me what I'm doing wrong?

Geoff
 
Not an expert but I would expect something like

Do While dview.Count > 0
dview.Delete(1)
Loop

Regards John

Or

Set dview = Nothing

:-)
 
Geoff,

Be aware two three, deleting of rows in a datatable (in fact are you doing
that) is one of the major AdoNet improvements in 2.0 because it is very
slow. If it is a complete table, than it is version 1.x probably better to
construct that table new. There is as well the command table.clear however
AFAIK is that as well slow in 1.x however than in 2.0 probably the best to
use to clear a complete table.

If you use the dataview with a rowfilter to delete a part of the table, than
I prefer the bottom up "for index".

For i as integer = dv.count - 1 until 0
dv(i).delete
Next

The advantage from this (not in this case) above the while loop is that if
you want to skip one datarow in the loop it keeps working.

I hope this helps,

Cor
 
Many thanks everyone for your help.

Geoff

Cor Ligthert said:
Geoff,

Be aware two three, deleting of rows in a datatable (in fact are you doing
that) is one of the major AdoNet improvements in 2.0 because it is very
slow. If it is a complete table, than it is version 1.x probably better to
construct that table new. There is as well the command table.clear however
AFAIK is that as well slow in 1.x however than in 2.0 probably the best to
use to clear a complete table.

If you use the dataview with a rowfilter to delete a part of the table,
than I prefer the bottom up "for index".

For i as integer = dv.count - 1 until 0
dv(i).delete
Next

The advantage from this (not in this case) above the while loop is that if
you want to skip one datarow in the loop it keeps working.

I hope this helps,

Cor
 

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

Back
Top