Solved

compare datasets

Posted on 2012-04-13
5
243 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
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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

Suggested Solutions

IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

813 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now