Avatar of NevSoFly
NevSoFly

asked on 

problem deleting datarow in datatable

I am using the attached code to remove datarows from on datatable that match datarows in another datatable.  The problem is that the row count for that datatable doesn't change and once the last datarow that I need to be deleted has been processed I get the following error.

DeletedRowInaccessibleException was unhandled.
Deleted row information cannot be accessed through the row.

I can't view the datatable using the data table visualizer because this causes an error in VS:

Unhandled exception
Deleted row information cannot be accessed through the row.





If dtTemp.Rows.Count > 0 And dtAssembly.Rows.Count > 0 Then
            For Each drclient As DataRow In dtAssembly.Rows
                For Each drServer As DataRow In dtTemp.Rows
                    If drclient("ASSEMBLY_NUMBER") = drServer("ASSEMBLY_NUMBER") Then drclient.Delete()
                Next drServer
                If dtTemp.Rows.Count = 0 Then Exit For
            Next drclient
        End If

Open in new window

Visual Basic.NET

Avatar of undefined
Last Comment
NevSoFly
Avatar of MijaeDjinn
MijaeDjinn
Flag of Canada image

If "ASSEMBLY_NUMBER" is unique (only one possible row for each "ASSEMBLY_NUMBER" ) in the dtAssembly table then you can just add:

Exit For

After drclient.Delete().


If "ASSEMBLY_NUMBER" is a key then you could do this using:
dtAssembly.FindByASSEMBLY_NUMBER()
and
dtAssembly.Rows.Contains( Your_Assembly_Number_Here )

If drclient("ASSEMBLY_NUMBER") = drServer("ASSEMBLY_NUMBER") Then 
  drclient.Delete()
  Exit For
End If

Open in new window

Avatar of NevSoFly
NevSoFly

ASKER

Thanks for your response.  This doesn't solve my problem as after the drServer.Delete dtTemp.rows.count still has not changed even tho drServer.rowstate= deleted.
ASKER CERTIFIED SOLUTION
Avatar of MijaeDjinn
MijaeDjinn
Flag of Canada image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of NevSoFly
NevSoFly

ASKER

Thank you please feel free to help me out on any other questions that you see from me.
Visual Basic.NET
Visual Basic.NET

Visual Basic .NET (VB.NET) is an object-oriented programming language implemented on the .NET framework, but also supported on other platforms such as Mono and Silverlight. Microsoft launched VB.NET as the successor to the Visual Basic language. Though it is similar in syntax to Visual Basic pre-2002, it is not the same technology,

96K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo