Solved

data type mismatch with an Access autonumber field

Posted on 2001-07-24
8
301 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
  • 3
  • 2
  • 2
  • +1
8 Comments
 

Expert Comment

by:ejrhodes
Comment Utility
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
Comment Utility
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
Comment Utility
I mean try this

sql = "SELECT * FROM track WHERE [ID] =" & ID
0
 
LVL 7

Expert Comment

by:John844
Comment Utility
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
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 
LVL 7

Expert Comment

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

Expert Comment

by:ejrhodes
Comment Utility
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
Comment Utility
no problem.  Just here to learn and try to help where I can
0
 
LVL 10

Author Comment

by:KenAdney
Comment Utility
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

What Security Threats Are You Missing?

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

Suggested Solutions

Title # Comments Views Activity
Set cursor to client side 3 48
two-way Authentication ASP 3 69
API not working 33 47
Voice recognition ASP or ASP.NET or JavaScript 2 43
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…
This demonstration started out as a follow up to some recently posted questions on the subject of logging in: http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28634665.html and http://www.experts-exchange.com/Programming/…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

763 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

13 Experts available now in Live!

Get 1:1 Help Now