Find value in DataSet

S

shapper

Hello,

I have 2 data sets: dsLevels and dsLevelsSubscribed.

And I created this loop:

For Each row As DataRow In dsLevels.Tables(0).Rows
??? row("LevelName")
Next row

I need to check if there is any row in dsLevelsSubscribed with the
same value in column "LevelName" as in row("LevelName").

If there is, I need to remove the row from dsLevels.

I have been trying to make this work but until now I add no success.

Could someone, please, help me out?

Thanks,

Miguel
 
S

shapper

DataTable class has Select method where you can specify filtering condition:

dsLevelsSubscribed.Tables(0).Select(String.Format("LevelName='{0}'",row("LevelName")))

--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]http://msmvps.com/blogs/egoldinhttp://usableasp.net


I have 2 data sets: dsLevels and dsLevelsSubscribed.
And I created this loop:
For Each row As DataRow In dsLevels.Tables(0).Rows
??? row("LevelName")
Next row
I need to check if there is any row in dsLevelsSubscribed with the
same value in column "LevelName" as in row("LevelName").
If there is, I need to remove the row from dsLevels.
I have been trying to make this work but until now I add no success.
Could someone, please, help me out?

Miguel

Hi,

I am using this:

' Remove subscribed levels from dsLevels
For Each drLevel As DataRow In dsLevels.Tables(0).Rows

' Find if level is subscribed
Dim drSubscribedLevel() As DataRow =
dsLevelsSubscribed.Tables(0).Select(String.Format("LevelName='{0}'",
drLevel("LevelName")))

' Remove level if it is subscribed
If Not drSubscribedLevel Is Nothing Then
dsLevels.Tables(0).Rows.Remove(drLevel)
End If

Next drLevel

However, I am getting the error:
Collection was modified; enumeration operation might not execute.

on Next drLevel

I suppose it is because I am removing rows during the loop.

How can I solve this?

Thanks,
Miguel
 
E

Eliyahu Goldin

Loop in another direction, from the last item to the first.

--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin
http://usableasp.net


shapper said:
DataTable class has Select method where you can specify filtering
condition:

dsLevelsSubscribed.Tables(0).Select(String.Format("LevelName='{0}'",row("LevelName")))

--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP
[ASP.NET]http://msmvps.com/blogs/egoldinhttp://usableasp.net


I have 2 data sets: dsLevels and dsLevelsSubscribed.
And I created this loop:
For Each row As DataRow In dsLevels.Tables(0).Rows
??? row("LevelName")
Next row
I need to check if there is any row in dsLevelsSubscribed with the
same value in column "LevelName" as in row("LevelName").
If there is, I need to remove the row from dsLevels.
I have been trying to make this work but until now I add no success.
Could someone, please, help me out?

Miguel

Hi,

I am using this:

' Remove subscribed levels from dsLevels
For Each drLevel As DataRow In dsLevels.Tables(0).Rows

' Find if level is subscribed
Dim drSubscribedLevel() As DataRow =
dsLevelsSubscribed.Tables(0).Select(String.Format("LevelName='{0}'",
drLevel("LevelName")))

' Remove level if it is subscribed
If Not drSubscribedLevel Is Nothing Then
dsLevels.Tables(0).Rows.Remove(drLevel)
End If

Next drLevel

However, I am getting the error:
Collection was modified; enumeration operation might not execute.

on Next drLevel

I suppose it is because I am removing rows during the loop.

How can I solve this?

Thanks,
Miguel
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,773
Messages
2,569,594
Members
45,119
Latest member
IrmaNorcro
Top