Solved

compare datasets

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

919 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

18 Experts available now in Live!

Get 1:1 Help Now