Solved

Date mismatch when using number type in Access

Posted on 2004-04-17
3
285 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
[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 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

Enroll in June's Course of the Month

June's Course of the Month is now available! Every 10 seconds, a consumer gets hit with ransomware. Refresh your knowledge of ransomware best practices by enrolling in this month's complimentary course for Premium Members, Team Accounts, and Qualified Experts.

Question has a verified solution.

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

Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
This is a high-level webinar that covers the history of enterprise open source database use. It addresses both the advantages companies see in using open source database technologies, as well as the fears and reservations they might have. In this…
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…

734 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