Solved

data type mismatch with an Access autonumber field

Posted on 2001-07-24
8
307 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 50 total points
ID: 6315430
I mean try this

sql = "SELECT * FROM track WHERE [ID] =" & ID
0
Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

 
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

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!

Question has a verified solution.

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

I recently decide that I needed a way to make my pages scream on the net.   While searching around how I can accomplish this I stumbled across a great article that stated "minimize the server requests." I got to thinking, hey, I use more than one…
Hello, all! I just recently started using Microsoft's IIS 7.5 within Windows 7, as I just downloaded and installed the 90 day trial of Windows 7. (Got to love Microsoft for allowing 90 days) The main reason for downloading and testing Windows 7 is t…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

717 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