473,503 Members | 1,864 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

ADO itterate datatable & delete row

Hi,

I am trying to itterate through a datatable and delete selected rows but I
get an error stating that the collection has changed when the row is
deleted.

Try
For Each drOrds In dsRecPurchs.Tables("PurchaseRecpts").Rows
If cBool(drOrds("Uploaded")) then
drOrds.Delete
End If
Next
Catch Ex As Exception
st=Ex.ToString
MessageBox ( st )
End Try
How do I itterate and Delete or batch Delete for a set criteria?

Thanks Doug
Nov 21 '05 #1
2 1784
Hi,

You cant use a for each loop to delete records. Use a for next
loop

Dim drOrds as datarow
Try
For x as integer = dsRecPurchs.Tables("PurchaseRecpts").Rows.count -1 to 0
step -1
drOrds = dsRecPurchs.Tables("PurchaseRecpts").Rows(x)
If cBool(drOrds("Uploaded")) then
drOrds.Delete
End If
Next
Catch Ex As Exception
st=Ex.ToString
MessageBox ( st )
End Try

Ken
---------------------
"Doug Versch" <du**@hotmail.com> wrote in message
news:eG****************@TK2MSFTNGP14.phx.gbl...
Hi,

I am trying to itterate through a datatable and delete selected rows but I
get an error stating that the collection has changed when the row is
deleted.

Try
For Each drOrds In dsRecPurchs.Tables("PurchaseRecpts").Rows
If cBool(drOrds("Uploaded")) then
drOrds.Delete
End If
Next
Catch Ex As Exception
st=Ex.ToString
MessageBox ( st )
End Try
How do I itterate and Delete or batch Delete for a set criteria?

Thanks Doug

Nov 21 '05 #2
Thanks Ken

"Ken Tucker [MVP]" <vb***@bellsouth.net> wrote in message
news:ev*****************@TK2MSFTNGP11.phx.gbl...
Hi,

You cant use a for each loop to delete records. Use a for next loop

Dim drOrds as datarow
Try
For x as integer = dsRecPurchs.Tables("PurchaseRecpts").Rows.count -1 to 0
step -1
drOrds = dsRecPurchs.Tables("PurchaseRecpts").Rows(x)
If cBool(drOrds("Uploaded")) then
drOrds.Delete
End If
Next
Catch Ex As Exception
st=Ex.ToString
MessageBox ( st )
End Try

Ken
---------------------
"Doug Versch" <du**@hotmail.com> wrote in message
news:eG****************@TK2MSFTNGP14.phx.gbl...
Hi,

I am trying to itterate through a datatable and delete selected rows but I
get an error stating that the collection has changed when the row is
deleted.

Try
For Each drOrds In dsRecPurchs.Tables("PurchaseRecpts").Rows
If cBool(drOrds("Uploaded")) then
drOrds.Delete
End If
Next
Catch Ex As Exception
st=Ex.ToString
MessageBox ( st )
End Try
How do I itterate and Delete or batch Delete for a set criteria?

Thanks Doug

Nov 21 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
15729
by: frank | last post by:
I have two DataTables, A and B. Both have the primary key "CID". How do I remove all entries in Table A from Table B (with the same PK)?
0
1314
by: Mark Jones | last post by:
I'm trying to delete a row from a DataGrid using a ButtonColumn with CommandName="Delete" by deleting the row in the underlying DataTable datasource, but it doesn't seem to be working at the...
1
315
by: Jarod | last post by:
Hey I have dataTable let's call it dtMessages, and I have dvUserMessages. I am doing st like this: dvUserMessages = dtMessages.defaultView; dvUserMessages.rowFilter = "User = 'John'"; than, I...
2
1979
by: John A Grandy | last post by:
anyone know why this is ? Imports System.Data Imports System.Diagnostics Public Class WebForm12
1
9790
by: Gary | last post by:
Hi, I have a DataTable, which will have 2 Columns, one column holds Unique values. I will use DataTable.Select(Unique value) and Filter the Matching rows, After filtering those rows I want...
3
3361
by: elziko | last post by:
I have a DataTable bound to a DataGrid. When a user clicks on a row on the DataGrid I use: MyDataTable.Rows(MyDatagrid.CurrentRowIndex).Item(0) to do some work with the value in the first cell...
3
1707
by: Fred Nelson | last post by:
Hi: I have created a datatable and I'm able to access it by key values. I need to be able to go to the "top" of the datatable and process records sequentially until they are completed. I...
1
4551
by: Jon | last post by:
Question: does datagrid1.isSelected(i) point to the same row as datatable.row(i).delete after datagrid sorted?? I am using datagrid1.isSelected(i) to identify datatable rows that have been...
3
5380
by: Niyazi | last post by:
Hi all, I have a dataTable that contains nearly 38400 rows. In the dataTable consist of 3 column. column 1 Name: MUHNO column 2 Name: HESNO Column 3 Name: BALANCE Let me give you some...
0
7287
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,...
0
7467
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5592
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,...
1
5021
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...
0
4685
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...
0
3175
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...
0
3166
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1519
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
744
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.