Findrows doesnt appear to be working on multiples

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • RSH

    #1

    Findrows doesnt appear to be working on multiples

    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( )




  • Cor Ligthert [MVP]

    #2
    Re: Findrows doesnt appear to be working on multiples

    RSH,

    Probably is this method simpler in this case

    http://msdn.microsoft.com/library/de...sfindtopic.asp

    I hope this helps,

    Cor


    Comment

    • RSH

      #3
      Re: Findrows doesnt appear to be working on multiples

      Good suggestion...it almost worked :-)

      Here is what I ended up with:


      Sub main()

      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")

      oSQLConn.Open()

      daCust.Fill(dsC ust, "Customers" )

      Dim colPk(2) As DataColumn

      colPk(0) = dsOldCust.Table s("OldCustomers ").Columns("FN" )

      colPk(1) = dsOldCust.Table s("OldCustomers ").Columns("LN" )

      dsOldCust.Table s("OldCustomers ").PrimaryK ey = colPk

      Dim i As Integer

      For i = 0 To dsCust.Tables(" Customers").Row s.Count - 1

      Dim foundRow As DataRow

      Dim findTheseVals(1 ) As Object

      strFN = dsCust.Tables(" Customers").Row s(i).Item("FN")

      strLN = dsCust.Tables(" Customers").Row s(i).Item("LN")

      findTheseVals(0 ) = dsCust.Tables(" Customers").Row s(i).Item("FN")

      findTheseVals(1 ) = dsCust.Tables(" Customers").Row s(i).Item("LN")

      foundRow = dsOldCust.Table s("OldCustomers ").Rows.Find(fi ndTheseVals)

      If Not (foundRow Is Nothing) Then

      Console.WriteLi ne(foundRow(2). ToString() & " " & foundRow(1).ToS tring())

      End If

      Next

      End Sub





      "Cor Ligthert [MVP]" <notmyfirstname @planet.nl> wrote in message
      news:O2DLV1onFH A.2904@tk2msftn gp13.phx.gbl...[color=blue]
      > RSH,
      >
      > Probably is this method simpler in this case
      >
      > http://msdn.microsoft.com/library/de...sfindtopic.asp
      >
      > I hope this helps,
      >
      > Cor
      >[/color]


      Comment

      Working...