?
Solved

data type mismatch with an Access autonumber field

Posted on 2001-07-24
8
Medium Priority
?
308 Views
Last Modified: 2008-03-17
I'm trying to pull a record from an Access2K database to edit it.  The field "ID" is the autonumbered key.  Here's the code...

<% ID = Request.querystring("ID")
   ID = CLng(ID)

Set DataConn = Server.CreateObject("ADODB.Connection")
Set rs = Server.CreateObject("ADODB.Recordset")

DataConn.Open "DBQ=" & Server.Mappath("disclosure.mdb") & ";Driver={Microsoft Access Driver (*.mdb)};"

sql = ("SELECT * FROM track WHERE [ID] = '" & ID & "'")
rs.Open sql, DataConn, 1, 3 %>

A VarType command confirms that "ID" is a long integer whether from the querystring and when it comes in from the database.  

TIA,

Ken
0
Comment
Question by:KenAdney
[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
  • 2
  • 2
  • +1
8 Comments
 

Expert Comment

by:ejrhodes
ID: 6315328
The only thing I can think of is the quotes around ID are messing you up. I could be mistaken, but I believe if you remove the quotes, it will recognize ID and your query will work.
0
 
LVL 4

Expert Comment

by:mberumen
ID: 6315427
I agree with Ejrhodes.    The apostrophe ' around the ID variable makes it become a string instead of a number

Try this instead

sql = ("SELECT * FROM track WHERE [ID] =" & ID & ")"
0
 
LVL 4

Accepted Solution

by:
mberumen earned 200 total points
ID: 6315430
I mean try this

sql = "SELECT * FROM track WHERE [ID] =" & ID
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 7

Expert Comment

by:John844
ID: 6315437
get rid of the parenthesis as well.  I have also seen some weird things happen with spacing in the where statements.  Don't add any spaces before or after the = sign.

change
sql = ("SELECT * FROM track WHERE [ID] = '" & ID & "'")
to
sql = "SELECT * FROM track WHERE [ID]=" & ID
0
 
LVL 7

Expert Comment

by:John844
ID: 6315441
If this does not fix your problem, post us the exact error message.
0
 

Expert Comment

by:ejrhodes
ID: 6315618
John I believe the ' are the big problem he is having and should fix it.  That being said,  I did not know about problems with ()  Thanks for the heads up
0
 
LVL 7

Expert Comment

by:John844
ID: 6315626
no problem.  Just here to learn and try to help where I can
0
 
LVL 10

Author Comment

by:KenAdney
ID: 6318004
Yep, that was ticket.  Thanks!

I guess I was reconverting the querystring back into a string, eh?  I have a hard time getting the syntax on those SQL statements right...
0

Featured Post

New benefit for Premium Members - Upgrade now!

Ready to get started with anonymous questions today? It's easy! Learn more.

Question has a verified solution.

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

I would like to start this tip/trick by saying Thank You, to all who said that this could not be done, as it forced me to make sure that it could be accomplished. :) To start, I want to make sure everyone understands the importance of utilizing p…
Have you ever needed to get an ASP script to wait for a while? I have, just to let something else happen. Or in my case, to allow other stuff to happen while I was murdering my MySQL database with an update. The Original Issue This was written…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Suggested Courses

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