Solved

Data type mismatch in criteria expression

Posted on 2014-02-25
3
332 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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Suggested Solutions

Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
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…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

760 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

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now