records comparison with ado.net

Kris71

Member
Joined
Sep 30, 2004
Messages
5
Programming Experience
Beginner
Hi,
i am new to vb.net and i have to rewrite a vb6 project.
I need to read from an indexed recordset one record at a time and compare data with records of another indexed recordset; if data are different or a record is missing I write a line of error in a list box.
Which is the best way to do this with vb.net and ado.net ? Could anyone help me with some code examples ?

This is my old vb6 code with ado

the record of rst1 and rst2 have these four fields :
Article;Colour;Size;Quantity

with rst1
.movefirst
rst2.movefirst
do until .eof
rst2.seek array(!Article, !Colour, !Size), adseekfirsteq
if rst2.eof then
...write error record missing
else
if rst2!quantity <> rst1!quantity then
... write error quantity is different
end if
end if
.movenext
loop
end with

Thank you
 
I don't have notion such as Microsoft ACCESS treated i'm develop with sql server however some things to have itself seriously changed on Vb.net.
e.g. there are no more recordsets....
It's really hard to explain this, but if you really transfer from vb6 then i recommend you:
Buy as fast as possible a book....

It's hard to say where to begin....:)
 
I do agree with MatrixMatrix that you need to find a book and do some reading, but here is some code that may help you solve your problem:

VB.NET:
' rst1 is now DataSet1 not a recordset
' rst2 is now DataSet2 not a recordset
' Can do this with just one DataSet as well 
' since a dataset supports multiple DataTables, 
' but I thought I'd keep it as close to the original as I could.
' you will have to find the code to load the DataSets with the required Data

Dim table1 as DataTable
Dim table2 as DataTable
table1 = DataSet1.Tables("TableName")
table2 = DataSet2.Tables("TableName")

Dim myRow as DataRow
For Each myRow in table1.Rows
   Dim strSearchExpression as String
   strSearchExpression = "Article = '" & myRow.Item("Article") & "' AND "
   strSearchExpression &= "Colour = '" & myRow.Item("Colour") & "' AND "
   strSearchExpression &= "Size = '" & myRow.Item("Size") & "'"

   Dim foundRows() As DataRow
   ' Use the Select method to find all rows matching the filter.
   foundRows = table2.Select(strSearchExpression)

   if foundrows.Count = 0 then
      ...write error record missing
   else
      if myRow.Item("Quantity") <> foundRows(0).Item("Quantity") then
         ... write error quantity is different
      end if
   End If
Next

Please note that I have noted tested this code as I do not have appropriate data, and alot of this was written from memory, you may have to read the help files if you run into problems.

Please not that it does not matter if the data comes from Access, SQL, Oracle, MySQL, a Text File, Excel File, or anywhere else. All that matters is that you are able to correctly load the data into a DataSet. Please think of a DataSet as an "in memory database"
 
Last edited:
Thank you very much, i put the code in my project with some changes and it works ok.
I think foundrows.count is foundrows.length instead, isn't it?

However I ordered a big book about Ado.net...

Thank you, bye
kris
 
Yeah That seems right that it should be length because it is an array object.....

Have fun reading the book, and feel free to keep on posting here.

Also Google is a pretty good resource....
 
Back
Top