Solved

data type mismatch with an Access autonumber field

Posted on 2001-07-24
8
304 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
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
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

 
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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Suggested Solutions

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…
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…
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…
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…

813 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

16 Experts available now in Live!

Get 1:1 Help Now