Interview Question in Sql Server Views


 

Interview Question :: ASP Error when viewing details for specific record in Access DB


I am using classic ASP / VBScript and Access for a DB. On the first page, I have a dynamic link which goes to a details page for a record in the images table of my DB.

The link on the first page looks like this:

http://www.mydomain.net/cp/cp-phoDel.asp...

The code I am using in the details page to set the RS is this:

sql = "SELECT * FROM images WHERE id = '" & id & "'"
Set rsPho = Server.CreateObject("ADODB.Recordset")
rsPho.Open sql, conn, 3, 3

"id" is a field in the images table of the database. It's data type is set to autoNumber and for some reason I get the feeling that's part of my problem. Since this is the only unique identifier in the table, I need to use it, but I think I'm calling it wrong in my sql.

This is the error I'm getting.
Microsoft JET Database Engine error '80040e07'

Data type mismatch in criteria expression.

/cp/cp-phoDel.asp, line 21

That line is the sql i pasted at the top.

Thanks guys.
Answers to "ASP Error when viewing details for specific record in Access DB"
RE: ASP Error when viewing details for specific record in Access DB?

You are correct. The problem is that, in the sql statement, you are enclosing the id field in quotes, which is telling the system that it should be comparing on a text field, not a number field. Since id is actually a number field, it's returning an error.



Remove both single-quotes (before and after), and you should be fine.



sql = "SELECT * FROM images WHERE id = " & id
 
Vote for this answer ::  
RE: ASP Error when viewing details for specific record in Access DB?

Enclosing quotes are not an issue.

Check with debugger what value is in "id" variable (& id &). I suppose it is not integer.
 
Vote for this answer ::  
Update Alert Setting