• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 347
  • Last Modified:

Data type mismatch in criteria expression

Dim holdlong As Long = CLng(Dst4.Tables(0).Rows(0).Item(0))
                Dim DadSocSec As OleDbDataAdapter = New OleDbDataAdapter("Select * From EmployeeCompInfo where EMPLOYEEID= '" & holdlong & "'  ", Con)

holdlong is a 3
EMPLOYEEID is a field with a 3 in it
Dim DstSocSec As DataSet = New DataSet
                DadSocSec.Fill(DstSocSec)
at this point I get this error: Data type mismatch in criteria expression
usually when you see this error the field is spelled wrong but it is not.
EMPLOYEEID is a long because it is the reference back to a another table which is the auto number primary key;  auto numbers are longs.  I cast it just to make sure, but no matter it comes up as 3.

if I get rid of the where clause the query runs just fine, so the data mismatch is in the where clause but I don't see it.

any suggestions??????
thanks

gary
0
javagair
Asked:
javagair
1 Solution
 
Paul JacksonCommented:
Remove the single apostrophes around holdlong variable because you have these it sees it as a string rather than a numeric :

Dim holdlong As Long = CLng(Dst4.Tables(0).Rows(0).Item(0))
                Dim DadSocSec As OleDbDataAdapter = New OleDbDataAdapter("Select * From EmployeeCompInfo where EMPLOYEEID= " & holdlong, Con)
0
 
John_VidmarCommented:
I thought the problem was you are concatenating a string to a long, would this help:
Dim holdlong	As Long			= CLng(Dst4.Tables(0).Rows(0).Item(0))
Dim DadSocSec	As OleDbDataAdapter	= New OleDbDataAdapter("Select * From EmployeeCompInfo where EMPLOYEEID= " & CStr(holdlong), Con) 

Open in new window

0
 
javagairAuthor Commented:
I should have caught that.
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now