Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

Hello,

 

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

 

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!

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...