Solved

Date mismatch when using number type in Access

Posted on 2004-04-17
3
261 Views
Last Modified: 2010-04-24
Hi,

I used to use String type for all my variable types in my Access DB even for variables with number types like IDs.

Due to some constraints i have to use Number types for my IDs now.

Here is an example of my SQL which has a data mismatch error.

Dim item As Integer
item = Request.QueryString("topicID")

Cmd = New OleDb.OleDbCommand("Select topicID ForumPosts where topicID ='" + item + "'", Conn)

I have also tried enclosing item in  only double quotes "+item+" or single quotes '+item+', and still the same error occurs.

It produces a data mismatch error. So what is the problem lying here?
0
Comment
Question by:FYPJ
3 Comments
 
LVL 16

Expert Comment

by:burakiewicz
Comment Utility
for integers in access you don't use any quotes ex
Cmd = New OleDb.OleDbCommand("Select topicID ForumPosts where topicID =" + item + ", Conn)
0
 
LVL 44

Accepted Solution

by:
Arthur_Wood earned 50 total points
Comment Utility
minor correction to the answer above:

Should read:

Cmd = New OleDb.OleDbCommand("Select topicID ForumPosts where topicID =" & item , Conn)

there is no need for the closing "", and the concatenation operator (to append a value to a string, is the & operator, not the + operator.

Since Item is declared as an Integer, you must use it that way.  in the SQL that you originally had, you are trying to compare a STRING (the '<itemvalu>' is a string), with a Number (the field in the table is of type number, hence the type mismatch.

Also, the + operator is trying to ADD (like 1+2) numbers, and you have a string on one side and a number on the other, and that ALSO gives a type Mismatch error.

AW
0
 

Author Comment

by:FYPJ
Comment Utility
OK thanks for both the answers.
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

762 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

12 Experts available now in Live!

Get 1:1 Help Now