?
Solved

Data type mismatch in criteria expression

Posted on 2014-02-25
3
Medium Priority
?
341 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 29

Accepted Solution

by:
Paul Jackson earned 2000 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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.

Question has a verified solution.

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

If you find yourself in this situation “I have used SELECT DISTINCT but I’m getting duplicates” then I'm sorry to say you are using the wrong SQL technique as it only does one thing which is: produces whole rows that are unique. If the results you a…
Occasionally there is a need to clean table columns, especially if you have inherited legacy data. There are obviously many ways to accomplish that, including elaborate UPDATE queries with anywhere from one to numerous REPLACE functions (even within…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses
Course of the Month11 days, 5 hours left to enroll

770 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