Error in ADODB.Connection Statement

MarkItZero

Active member
Joined
Apr 10, 2003
Messages
43
Location
under the desk in my office
Hello,

I have a program that connects to an Access database. I use an ADODB Connection to bring the data into my program.

Code:
Public HeaderID as Integer

Private Sub FrmExistingEstimate_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
 Open ADODB Connection
        Dim cnn1 As New ADODB.Connection()
        cnn1.Open("Provider=Microsoft.Jet.OLEDB.4.0;" & _
        "Data Source=C:\Visual Studio Projects\Estimate\EstimatesDB.mdb;", _
        "Admin", "")

        Query
        Dim Str1 As String = "Select * from EstHeader Where HeaderID = " & HeaderID & ""
        Open RecordSet
        With rst1
            .ActiveConnection = cnn1
            .Open(Str1, , _
            ADODB.CursorTypeEnum.adOpenKeyset, _
            ADODB.LockTypeEnum.adLockOptimistic)
        End With

Previously, I used the same code, however, the SQL string was slightly different. I checked the JobName field in the Where statement. And everything worked fine. But when I change the Where statement to check the primary key of the table HeaderID (an autonumber field). I got this error...

An unhandled exception of type System.Runtime.InteropServices.COMException occurred in ServiceEstimateApp.exe

Additional information: Data type mismatch in criteria expression.

..pointing at the .Open(Str.... portion of the code.


Any ideas on what might be wrong?

Thank you!
 
When using numeric values dont use the single quotes...
Code:
Dim Str1 As String = "Select * from EstHeader Where HeaderID = " & HeaderID
 
Back
Top