Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Deleting a row
Message
From
02/01/2011 19:19:06
 
 
To
02/01/2011 19:00:34
General information
Forum:
ASP.NET
Category:
Coding, syntax and commands
Title:
Environment versions
Environment:
VB 9.0
OS:
Windows 7
Network:
Windows 2003 Server
Database:
MS SQL Server
Application:
Web
Miscellaneous
Thread ID:
01494343
Message ID:
01494356
Views:
61
This message has been marked as the solution to the initial question of the thread.
The problem is most likely that you should delete backwards, IOW go from RowCount-1 to 0. So, I bet if you structured your Delete like this, it would work:
            ' For each message
            ' I just realized I don't know how to negatively decrement in VB
            ' you'll have to fill in the blanks on that one
            ' In C# it would be:
            ' for (lnCounter = loDataProvider.nCount - 1; lnCounter >=0; lnCounter--)
            For lnCounter = loDataProvider.nCount - 1 To 0
                loRow = loDataProvider.oDataSet.Tables("Temp").Rows(lnCounter)

                ' If we have to delete the row
                If True Then
                    loRow.Delete()
                End If

            Next
Deleting forward rather than backward will work only if you have no rows with a RowState of Added. An Added Row gets physically removed from the DataTable (decreasing the number of Rows in the Rows collection), whereas all other rows get changed to a RowState of Deleted and the number of Rows remain the same.

~~Bonnie




>>What code are you using that you get this error? A DataRow can call it's Delete() method with no problem. Are you doing something peculiar?
>
>I always have to do something like this:
>
>
>            loDataView = New DataView(loDataProvider.oDataSet.Tables.Item(0))
>
>            loDataView.RowFilter = "Flag=1"
>
>            ' Delete all records which have been flagged
>            For Each loRowView In loDataView
>                loRowView.Delete()
>            Next
>
>            loDataView.RowFilter = ""
>            loDataView.Table.AcceptChanges()
>
>            ' Adjust the count
>            loDataProvider.nCount = loDataProvider.oDataSet.Tables("Temp").Rows.Count
>
>
>Because, if I scan my dataset, and based on a condition, I want to remove the record, it will tell me that the Delete() method cannot be used:
>
>
>            ' For each message
>            For lnCounter = 0 To loDataProvider.nCount - 1
>                loRow = loDataProvider.oDataSet.Tables("Temp").Rows(lnCounter)
>
>                ' If we have to delete the row
>                If True Then
>                    loRow.Delete()
>                End If
>
>            Next
>
Bonnie Berent DeWitt
NET/C# MVP since 2003

http://geek-goddess-bonnie.blogspot.com
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform