Solved

Data type mismatch in criteria expression

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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

'Between' is such a common word we rarely think about it but in SQL it has a very specific definition we should be aware of. While most database vendors will have their own unique phrases to describe it (see references at end) the concept in common …
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

776 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