Solved

compare datasets

Posted on 2012-04-13
5
248 Views
Last Modified: 2012-04-16
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
Thanks
r3nder
0
Comment
Question by:r3nder
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 37843282
== 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)
      Next
Next
0
 
LVL 6

Author Comment

by:r3nder
ID: 37843527
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
                    RemoveUserFromGroup("userid")
                End If
                If Not (col2 = col) Then
                    AddMyUserToGroup("de", "username", "group")
                End If
            Next
        Next
    End Sub

Open in new window


Thank for the help
0
 
LVL 17

Accepted Solution

by:
nepaluz earned 250 total points
ID: 37844657
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
    Next
    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
    Next
End Sub

Open in new window

0
 
LVL 20

Assisted Solution

by:BuggyCoder
BuggyCoder earned 250 total points
ID: 37845626
try this:-
Dim dtOld = New DataTable()
dtOld.Columns.Add(New DataColumn("UserId"))
dtOld.Columns.Add("UserName")

Dim dtNew = New DataTable()
dtNew.Columns.Add("UserId")
dtNew.Columns.Add("OrderId")

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
Else
		'No Match Found
End If

Open in new window

0
 
LVL 6

Author Closing Comment

by:r3nder
ID: 37852026
thanks - did great with a little modification
0

Featured Post

Stack Overflow Podcast - Frustrating Miracles

In this podcast, Stack Overflow interviewed Linux Academy CEO/Founder, Anthony James, and got his developer story!

"Follow your passion, be prepared to work hard and sacrifice, and, above all, don't let anyone limit your dreams."  - Donovan Bailey

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…

636 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question