Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. Comparing Results between two Datareaders

Comparing Results between two Datareaders

Scheduled Pinned Locked Moved Visual Basic
csharpdatabasehelp
8 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    Sean Venter
    wrote on last edited by
    #1

    Hi All, I am new to VB.net and I am struggling with small function I need to write. Basically this function must get results from two different datareaders, Oledb and SQL and compare the results. Is using a datareader the right way of going about a comparison between two recordsets, or is there a better way. Basically I need to compare the results of the two recordsets and the differences must be noted in a file. Any help will be appreciated. Regards Scorn.

    K D 2 Replies Last reply
    0
    • S Sean Venter

      Hi All, I am new to VB.net and I am struggling with small function I need to write. Basically this function must get results from two different datareaders, Oledb and SQL and compare the results. Is using a datareader the right way of going about a comparison between two recordsets, or is there a better way. Basically I need to compare the results of the two recordsets and the differences must be noted in a file. Any help will be appreciated. Regards Scorn.

      K Offline
      K Offline
      Kanniah
      wrote on last edited by
      #2

      Hi You can go for Datasets, which is much easier to loop (as you can forward / rewind the dataset) you cannot do this in a datareader. All the Best! Kanniah

      S 1 Reply Last reply
      0
      • S Sean Venter

        Hi All, I am new to VB.net and I am struggling with small function I need to write. Basically this function must get results from two different datareaders, Oledb and SQL and compare the results. Is using a datareader the right way of going about a comparison between two recordsets, or is there a better way. Basically I need to compare the results of the two recordsets and the differences must be noted in a file. Any help will be appreciated. Regards Scorn.

        D Offline
        D Offline
        Dave Kreskowiak
        wrote on last edited by
        #3

        You can do this with DataReaders. They'll be faster and more memory efficient than loading entire sets of data. They also offer the flexibility of looking at millions of records without loading them all into RAM. After that, you just compare record for record, incrementing each DataReader to compare then next records.

        Dave Kreskowiak Microsoft MVP - Visual Basic

        S 2 Replies Last reply
        0
        • D Dave Kreskowiak

          You can do this with DataReaders. They'll be faster and more memory efficient than loading entire sets of data. They also offer the flexibility of looking at millions of records without loading them all into RAM. After that, you just compare record for record, incrementing each DataReader to compare then next records.

          Dave Kreskowiak Microsoft MVP - Visual Basic

          S Offline
          S Offline
          Sean Venter
          wrote on last edited by
          #4

          Hi Dave, Thanks for your reply, I will give your answer a try and see how I do. Regards Sean

          1 Reply Last reply
          0
          • K Kanniah

            Hi You can go for Datasets, which is much easier to loop (as you can forward / rewind the dataset) you cannot do this in a datareader. All the Best! Kanniah

            S Offline
            S Offline
            Sean Venter
            wrote on last edited by
            #5

            Hi Kanniah, I am going to try Dave's solution first as I would like to save on resources. Should I not get it right I will try your solution. Thanks for the reply. Regards Sean

            1 Reply Last reply
            0
            • D Dave Kreskowiak

              You can do this with DataReaders. They'll be faster and more memory efficient than loading entire sets of data. They also offer the flexibility of looking at millions of records without loading them all into RAM. After that, you just compare record for record, incrementing each DataReader to compare then next records.

              Dave Kreskowiak Microsoft MVP - Visual Basic

              S Offline
              S Offline
              Sean Venter
              wrote on last edited by
              #6

              Hi Dave, I need to pick your brain some more please. I have managed to get right what I wanted to do, however I would like to know if this is the correct way of doing it, or if there is a different way. Once again is this code resource effiecient? Public Function fnCheckClientMasterRecords() As Boolean Dim dbrAsiClients As SqlDataReader Dim dbrXpressClients As OleDbDataReader 'Two functions that return the records that I need to compare and populates my new datareaders dbrAsiClients = fnGetAllASIClients() dbrXpressClients = fnGetAllXpressClients() While Not dbrAsiClients.Read = False While Not dbrXpressClients.Read = False If Not Left(dbrAsiClients.GetValue(0).ToString(), 6) = Left(dbrXpressClients.GetValue(0).ToString(), 6) Then MessageBox.Show(Left(dbrAsiClients.GetValue(0).ToString(), 6) & " - " & Left(dbrXpressClients.GetValue(0).ToString(), 6)) Else 'Yes code here End If End While 'Do I have to close the reader here everytime I Have looped through it and re-populate it. dbrXpressClients.Close() dbrXpressClients = fnGetAllXpressClients() End While End Function Your input will be appreciated. Kind Regards Sean Venter

              D 1 Reply Last reply
              0
              • S Sean Venter

                Hi Dave, I need to pick your brain some more please. I have managed to get right what I wanted to do, however I would like to know if this is the correct way of doing it, or if there is a different way. Once again is this code resource effiecient? Public Function fnCheckClientMasterRecords() As Boolean Dim dbrAsiClients As SqlDataReader Dim dbrXpressClients As OleDbDataReader 'Two functions that return the records that I need to compare and populates my new datareaders dbrAsiClients = fnGetAllASIClients() dbrXpressClients = fnGetAllXpressClients() While Not dbrAsiClients.Read = False While Not dbrXpressClients.Read = False If Not Left(dbrAsiClients.GetValue(0).ToString(), 6) = Left(dbrXpressClients.GetValue(0).ToString(), 6) Then MessageBox.Show(Left(dbrAsiClients.GetValue(0).ToString(), 6) & " - " & Left(dbrXpressClients.GetValue(0).ToString(), 6)) Else 'Yes code here End If End While 'Do I have to close the reader here everytime I Have looped through it and re-populate it. dbrXpressClients.Close() dbrXpressClients = fnGetAllXpressClients() End While End Function Your input will be appreciated. Kind Regards Sean Venter

                D Offline
                D Offline
                Dave Kreskowiak
                wrote on last edited by
                #7

                If your comparing every record side-by-side against a corresponding record in the second dataset then you don't use two while loops. You use one. If your comparing every record in the first table with every other record in the second table, then this works. And yes, you have to reload the DataReader for each pass, since they a forward-only readers. You can't move the cursors in them backwards.

                Dave Kreskowiak Microsoft MVP - Visual Basic

                S 1 Reply Last reply
                0
                • D Dave Kreskowiak

                  If your comparing every record side-by-side against a corresponding record in the second dataset then you don't use two while loops. You use one. If your comparing every record in the first table with every other record in the second table, then this works. And yes, you have to reload the DataReader for each pass, since they a forward-only readers. You can't move the cursors in them backwards.

                  Dave Kreskowiak Microsoft MVP - Visual Basic

                  S Offline
                  S Offline
                  Sean Venter
                  wrote on last edited by
                  #8

                  Great, I do need to campare every record in the first table with every record in the second table. Thanks for the help.

                  Kind Regards Scorn

                  1 Reply Last reply
                  0
                  Reply
                  • Reply as topic
                  Log in to reply
                  • Oldest to Newest
                  • Newest to Oldest
                  • Most Votes


                  • Login

                  • Don't have an account? Register

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • World
                  • Users
                  • Groups