Solved

compare datasets

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

SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
asp.net, radiobuttonlist, c# 3 69
search by any word in column 5 29
SQL query joining 6 tables in asp.net 4 30
AD Computer Objects in VB .Net 2 15
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…
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…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

734 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