Solved

Date mismatch when using number type in Access

Posted on 2004-04-17
3
280 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
ID: 10849767
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
ID: 10849846
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
ID: 10852078
OK thanks for both the answers.
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

Suggested Solutions

Title # Comments Views Activity
Prevent call a sub/function several times when data bind to gridview 21 32
get row value in vb.net 4 17
VB.NET 2008 Publish Error 2 32
location of a form 2 24
1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
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.
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

790 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