By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,117 Members | 2,142 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,117 IT Pros & Developers. It's quick & easy.

Q: Deleting rows in a DataView

P: n/a
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
Nov 21 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
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" <no********@email.com> wrote in message
news:VL********************@pipex.net...
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

Nov 21 '05 #2

P: n/a
Better make that:

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

"JohnGriffiths" <Re***@ToGroupOnly.com> wrote in message
news:dj**********@newsg3.svr.pol.co.uk...
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" <no********@email.com> wrote in message
news:VL********************@pipex.net...
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


Nov 21 '05 #3

P: n/a
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


"Geoff" <no********@email.com> schreef in bericht
news:VL********************@pipex.net...
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

Nov 21 '05 #4

P: n/a
Many thanks everyone for your help.

Geoff

"Cor Ligthert [MVP]" <no************@planet.nl> wrote in message
news:u3**************@tk2msftngp13.phx.gbl...
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


"Geoff" <no********@email.com> schreef in bericht
news:VL********************@pipex.net...
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


Nov 21 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.