Comparing recordsets in VB2005

K

Kevin

I'm trying to convert a VB6 app to VB2005. I'm trying to search for
changes made to a record and record them in a log file. This is my
code in VB6:

Dim X As Long
Dim oField As ADODB.Field
Dim rs as New Adodb.Recordset

pstrSQL = "SELECT * FROM qryCRClasses WHERE fldStudentNumber = '" &
txtStudentNumber & "' AND fldCourseID = " & txtCourseID
rs.Open pstrStudent, db, adOpenStatic, adLockOptimistic, adCmdText
lFieldCount = rs.Fields.Count - 1

'Compare the new record to the one stored in the SavedRecord array

For X = 0 To lFieldCount
Set oField = rs.Fields(X)
If SavedRecord(X).Value <> oField.Value Then
kString = kString & oField.Name & " * " & oField.Value & " |
"
End If
Next


Worked well enough in VB6, but I get the error:
Operator '<>' is not defined for type 'DBNull' and type 'DBNull'

I think I need to use IComparer.Compare Method, but can't quite figure
out the syntax. Does anyone know of an easy way to do this?
 
C

Cor Ligthert [MVP]

Kevin,

The IComparer is to compare fields. It will not help you in this.

You get somehow DBNull values while your datafield is not from that value.

if Not oField.Value Is Dbnull.value

Will probably do your job.

I hope this helps,

Cor



If rs.Field(
 
K

Kevin

Right, I'm wanting to compare fields. But I took your advice and just
did it the easy way with the IF THEN statements. Thanks.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top