PC Review


Reply
Thread Tools Rate Thread

Delete DataView rows from DataTable (should be simple)

 
 
MattB
Guest
Posts: n/a
 
      21st Jun 2005
I'm using vb.net, but if you only have a c# answer, feel free to offer it!.

Anyway, I have a DataTable and a DataView which is a subset I have ID'd
to be deleted from that DataTable. I tried looping through the DataView
and deleting rows like this:

Dim dvAuto As New DataView
dvAuto.Table = dtCart
dvAuto.RowFilter = "AutoAdd = True"
If dvAuto.Count > 0 Then
Dim dr As DataRow
For Each dr In dvAuto.Table.Rows
dr.Delete()
Next
End If

But obviously it didn't work. I suspected modifying a collection while
looping through it would be a no-no and I was right (but tried anyway).

Without being able to issues a SQL delete like:
delete from dtCart where AutoAdd = True

I'm just not sure how to do this. How is this typically done? Thanks!

Matt
 
Reply With Quote
 
 
 
 
Chad Z. Hower aka Kudzu
Guest
Posts: n/a
 
      21st Jun 2005
MattB <(E-Mail Removed)> wrote in
news:(E-Mail Removed):
> Dim dr As DataRow
> For Each dr In dvAuto.Table.Rows
> dr.Delete()
> Next
> End If
>
> But obviously it didn't work. I suspected modifying a collection while
> looping through it would be a no-no and I was right (but tried
> anyway).


Use a for loop and count backwards. If ir you want to clear all, just call .Clear.


--
Chad Z. Hower (a.k.a. Kudzu) - http://www.hower.org/Kudzu/
"Programming is an art form that fights back"

Blog: http://blogs.atozed.com/kudzu
 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
datatable rows count and dataview count differ John Hui Microsoft ADO .NET 4 3rd Aug 2010 10:26 PM
DataTable -> DataView -> Sort -> DataGrid : need related DataTable index Diamonds Microsoft ADO .NET 4 28th Jun 2006 08:23 PM
Repost:Adding rows to DataTable and DataView issue Marina Microsoft ADO .NET 1 2nd May 2005 06:34 PM
Adding rows to DataTable and DataView issue Marina Microsoft ADO .NET 1 28th Apr 2005 06:14 PM
Using dataview/datatable to obtain range of rows vNeOsSePyAjM@dnb.com.au Microsoft ADO .NET 0 28th Aug 2003 08:19 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 10:22 PM.