Avatar of piemckay
piemckay
 asked on

ASP and SQL varchar value to data type int error

I pass a variable through my URL which is used as part of an SQL query.

But the query doesnt seem to like the variable.

Here is the error message and the URL is visible.

Browser Error
and here is the code:

<%
Dim rec_id
rec_id = Request.QueryString("code")
Dim Recordset1
Dim Recordset1_cmd
Dim Recordset1_numRows

Set Recordset1_cmd = Server.CreateObject ("ADODB.Command")
Recordset1_cmd.ActiveConnection = MM_objConnect_STRING
Recordset1_cmd.CommandText = "SELECT * FROM dbo.tblNews WHERE id='rec_id'" 
Recordset1_cmd.Prepared = true

Set Recordset1 = Recordset1_cmd.Execute
Recordset1_numRows = 0
%>

Open in new window


I tried casting rec_id with CInt but then I got "type mismatch with CInt".

I have also tried it without the quotes in the URL variable and the same problem.

Same Error
Any ideas?
ASPMicrosoft SQL Server 2005SQL

Avatar of undefined
Last Comment
Gerry Bartley

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
Gerry Bartley

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
piemckay

ASKER
OFCOURSE!!! urgh thanks

Didnt click thats how we join variables to strings in VB.
Gerry Bartley

Glad to help!
All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat
William Peck