I have a situation where I am filling two datasets and I need to print out
the names that appear in both datasets. I initially converted them to
dataviews, sorted on last name and performed a dataview.find on the view.
This indeed found the people that appeared in the two seperate databases
with the last name (as long as I performed a sort on the last name field
BEFORE finding). The issue immediately came up that i needed to check the
first name too. Well after searching for a bit I found the code i thought I
needed and put it in (see below) but it doesn't catch the matches, it
returns nothing everytime even though i have several matches intentionally
put in.
I have to use the datasets for comparision because the datasources with be
comparing from an Access database and a SQL Server database so a join query
will not work.
Any advice or help would be greatly appreciated.
Ron
Dim oSQLConn As SqlConnection = New SqlConnection(s trConn)
Dim daCust As SqlDataAdapter = New SqlDataAdapter( "SELECT * FROM
test.dbo.Custom ers", oSQLConn)
Dim daOldCust As SqlDataAdapter = New SqlDataAdapter( "SELECT * FROM
test.dbo.OldCus tomers", oSQLConn)
Dim cbCust As SqlCommandBuild er = New SqlCommandBuild er(daCust)
Dim strFN As String
Dim strLN As String
Dim dsCust As DataSet = New DataSet
Dim dsOldCust As DataSet = New DataSet
Dim intOldCustFNInd x As Integer
Dim intOldCustLNInd x As Integer
daOldCust.FillS chema(dsOldCust , SchemaType.Mapp ed, "OldCustome rs")
daOldCust.Fill( dsOldCust, "OldCustome rs")
Dim dvOldCust As New DataView
dvOldCust = dsOldCust.Table s("OldCustomers ").DefaultV iew
oSQLConn.Open()
daCust.Fill(dsC ust, "Customers" )
Dim i As Integer
For i = 0 To dsCust.Tables(" Customers").Row s.Count - 1
strFN = dsCust.Tables(" Customers").Row s(i).Item("FN")
strLN = dsCust.Tables(" Customers").Row s(i).Item("LN")
intOldCustFNInd x = 0
intOldCustLNInd x = 0
dvOldCust.Sort = "LN,FN"
Dim foundRows() As DataRowView = dvOldCust.FindR ows(New Object() {strFN,
strLN})
MessageBox.Show (foundRows.Leng th)
Dim cnt As DataRowView
For Each cnt In foundRows
Console.WriteLi ne("{0}, {1}", cnt("FN").ToStr ing(), cnt("LN").ToStr ing())
Next
oSQLConn.Close( )
the names that appear in both datasets. I initially converted them to
dataviews, sorted on last name and performed a dataview.find on the view.
This indeed found the people that appeared in the two seperate databases
with the last name (as long as I performed a sort on the last name field
BEFORE finding). The issue immediately came up that i needed to check the
first name too. Well after searching for a bit I found the code i thought I
needed and put it in (see below) but it doesn't catch the matches, it
returns nothing everytime even though i have several matches intentionally
put in.
I have to use the datasets for comparision because the datasources with be
comparing from an Access database and a SQL Server database so a join query
will not work.
Any advice or help would be greatly appreciated.
Ron
Dim oSQLConn As SqlConnection = New SqlConnection(s trConn)
Dim daCust As SqlDataAdapter = New SqlDataAdapter( "SELECT * FROM
test.dbo.Custom ers", oSQLConn)
Dim daOldCust As SqlDataAdapter = New SqlDataAdapter( "SELECT * FROM
test.dbo.OldCus tomers", oSQLConn)
Dim cbCust As SqlCommandBuild er = New SqlCommandBuild er(daCust)
Dim strFN As String
Dim strLN As String
Dim dsCust As DataSet = New DataSet
Dim dsOldCust As DataSet = New DataSet
Dim intOldCustFNInd x As Integer
Dim intOldCustLNInd x As Integer
daOldCust.FillS chema(dsOldCust , SchemaType.Mapp ed, "OldCustome rs")
daOldCust.Fill( dsOldCust, "OldCustome rs")
Dim dvOldCust As New DataView
dvOldCust = dsOldCust.Table s("OldCustomers ").DefaultV iew
oSQLConn.Open()
daCust.Fill(dsC ust, "Customers" )
Dim i As Integer
For i = 0 To dsCust.Tables(" Customers").Row s.Count - 1
strFN = dsCust.Tables(" Customers").Row s(i).Item("FN")
strLN = dsCust.Tables(" Customers").Row s(i).Item("LN")
intOldCustFNInd x = 0
intOldCustLNInd x = 0
dvOldCust.Sort = "LN,FN"
Dim foundRows() As DataRowView = dvOldCust.FindR ows(New Object() {strFN,
strLN})
MessageBox.Show (foundRows.Leng th)
Dim cnt As DataRowView
For Each cnt In foundRows
Console.WriteLi ne("{0}, {1}", cnt("FN").ToStr ing(), cnt("LN").ToStr ing())
Next
oSQLConn.Close( )
Comment