473,587 Members | 2,487 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Q: Deleting rows in a DataView

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
4 4646
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********@ema il.com> wrote in message
news:VL******** ************@pi pex.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
Better make that:

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

"JohnGriffi ths" <Re***@ToGroupO nly.com> wrote in message
news:dj******** **@newsg3.svr.p ol.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********@ema il.com> wrote in message
news:VL******** ************@pi pex.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
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********@ema il.com> schreef in bericht
news:VL******** ************@pi pex.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
Many thanks everyone for your help.

Geoff

"Cor Ligthert [MVP]" <no************ @planet.nl> wrote in message
news:u3******** ******@tk2msftn gp13.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********@ema il.com> schreef in bericht
news:VL******** ************@pi pex.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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
1515
by: Job Lot | last post by:
My DataGrid is bound to DataView as follow DataGrid1.DataSource = myDS.Tables("Client_Consultant").DefaultView User can either delete all the rows in the DataGrid on by pressing "Delete All" button or provide Client_Consulatnt_ID and press "Delete" button to delete rows with that Client_Consulatnt_ID. My question is: 1. How can i delete all the rows on click of a button. 2. How can i remove all the rows with particular...
1
4166
by: Junkguy | last post by:
I'm having difficulty deleting rows from a datagrid. I want to put a "delete" button on a form and achieve the same functionality as hitting the "delete" key on the keyboard for the selected row of a datagrid. I really want to do it generically so I have subclassed datagrid and made my own delete row method but I can only get it to work for datasources that are datatables or dataviews. Specifically when the datasource is a DataSet I...
5
14728
by: Mojtaba Faridzad | last post by:
Hi, with SetDataBinding( ) a DataGrid shows a DataView. user can select some rows in the grid by holding cotrol key. when user clicks on Delete button, I should delete all selected rows. I am trying to delete these lines from the dataview like this: for (int i=0; i < dataView.Count; i++) if (dataGrid.IsSelected(i)) dataView.Delete(i);
3
1753
by: Abra | last post by:
My C# application has a list (ListBox object), connected over a DataView to a dataset which corresponds to a table from a MySql database. I want to delete for example 4000-5000 rows from the table, which correspond to a certain filter. If I iterate the Rows from the table and check for each one the filter condition and, if true, I call the Delete() method, it takes several minutes till the respective rows are deleted. I tried also to...
1
1766
by: Derrick | last post by:
Hello; Sorry for being a little off topic. I've posted to the ADO.NET group as well :) Dealing with Winforms on 1.1 framework, VS.NET 2003. I have a DataView (which is the Data Source for a DataGrid), and I want to be able to delete rows only if specific columns contain specific values. For example, one of the columns contains boolean values; if the value for
4
2692
by: Peter | last post by:
I have the following code which retreives data from Excel spreadsheet. How do I exclude or delete records from the table that have blank first column, I do not need to write the records back. Thanks Peter
9
1718
by: Hamed | last post by:
Hello I have a DataGrid that a is bound to a DataTable. Some of the rows in the DataTable should not be deleted. How can I prohibit deleting of some identified rows? The problem could be specified in the following format too: There is a DataView object that I want to prohibit deleting of some of its DataRowView objects. that is: when drv.Delete() is called (drv is the
2
10009
by: HansP | last post by:
Hi, I am really in a deadlock with this problem. In my VS2005 C# handheld application, I have a grid with Workorders. Another grid (child) are the ACTIONS, performed for each workorder. Both grids have Dataviews as DataSource. The child grid, filtered with RowFilter in the DataView works fine.
8
1870
by: NAdir | last post by:
Hi, thank you for your help. My VB.Net application contains a document that the user can refresh at any time. The refresh works fine and needs to loop through few datatables (hundreds of rows). This works fine until I delete some rows in two tables. Just after the delete if I do the refresh there is a huge memory allocated and the time needed to perform the refresh increase, the memory and time continue to increase on each refresh until I...
0
8216
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8349
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
6629
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
5719
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5395
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
3845
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
3882
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1455
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1192
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.