Comparing Results between two Datareaders
-
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.
-
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.
-
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.
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
-
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
Hi Dave, Thanks for your reply, I will give your answer a try and see how I do. Regards Sean
-
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
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
-
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
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 -
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 VenterIf 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
-
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
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