Solved

Data type mismatch in criteria expression

Posted on 2014-02-25
3
336 Views
Last Modified: 2014-02-26
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
Comment
Question by:javagair
3 Comments
 
LVL 29

Accepted Solution

by:
Paul Jackson earned 500 total points
ID: 39887518
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
 
LVL 11

Expert Comment

by:John_Vidmar
ID: 39888748
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
 

Author Closing Comment

by:javagair
ID: 39889376
I should have caught that.
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
location of a form 2 25
Generate Numbers in JQuery file 11 66
2 IIF's in Access query 25 44
vb.net convert long time to mm:ss 23 13
Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question