compare datasets

I am trying to compare datasets. the ulimate goal is:
if  dataset1 column matches this dataset2 column - do nothing
if  dataset1 column is not in dataset2 column - run ad function
if  dataset2 column is not in dataset1 column - run remove function
How can I accomplish this?
        Dim ds As DataSet = fillMembers()
        Dim dsUser As DataSet = GetMyUsersinGroup()
        If ((ds.Tables("userid")) == (dsUser.Tables("username")) Then '<-- operator wrong

        End If

    End Sub

Open in new window

Help and logic is greatly appreciated
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

== is for C#.

You would need to loop through columns is tables

ForEach col as DataColumn In ds.Tables(0).Columns
      ForEach col2 as DataColumn In ds.Tables(1).Columns
           'comparison (may be on name)
r3nderAuthor Commented:
How about this: I get an error - Expression is of type 'System.Data.DataColumn', which is not a collection type.
and above that does my scenario above look like it matches this code?
    Public Sub compareDS()
        Dim group As String = "A GROUP"
        Dim ds As DataSet = fillMembers()
        Dim dsUser As DataSet = GetMyUsersinGroup()
        Dim col As String
        Dim col2 As String
        For Each col As DataColumn In ds.Tables(0).Columns("userid") '<--- Error here
            For Each col2 As DataColumn In dsUser.Tables(0).Columns("username")
                If (col = col2) Then
                    'Do nothing
                End If
                If Not (col = col2) Then
                End If
                If Not (col2 = col) Then
                    AddMyUserToGroup("de", "username", "group")
                End If
    End Sub

Open in new window

Thank for the help
try this
Public Sub compareDS()
    Dim ds1 As DataSet = fillMembers()
    Dim dsUser1 As DataSet = GetMyUsersinGroup()
    Dim tDS1 = (From x As DataColumn In ds1.Tables(0).Columns Select x.ColumnName).ToList
    Dim tUS1 = (From x As DataColumn In dsUser1.Tables(0).Columns Select x.ColumnName).ToList
    For Each x In tDS1
        If Not tUS1.Contains(x) Then
            'run add column
            Dim ToAdd = (From q As DataColumn In ds1.Tables(0).Columns Where q.ColumnName = x Select q).FirstOrDefault
        End If
    For Each x In tUS1
        If Not tDS1.Contains(x) Then
            'run remove column
            Dim ToRemove = (From q As DataColumn In dsUser1.Tables(0).Columns Where q.ColumnName = x Select q).FirstOrDefault
        End If
End Sub

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
try this:-
Dim dtOld = New DataTable()
dtOld.Columns.Add(New DataColumn("UserId"))

Dim dtNew = New DataTable()

Dim colOld = dtOld.Columns.Cast(Of DataColumn)()
Dim colNew = dtNew.Columns.Cast(Of DataColumn)()

If colOld.Any(Function(c) colNew.Any(Function(d) d.ColumnName = c.ColumnName)) Then
		'If Any Column Matches
		'No Match Found
End If

Open in new window

r3nderAuthor Commented:
thanks - did great with a little modification
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.