Link to home
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.

User generated image
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.

User generated image
Any ideas?
ASKER CERTIFIED SOLUTION
Avatar of Gerry Bartley
Gerry Bartley
Flag of Ireland image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of piemckay
piemckay

ASKER

OFCOURSE!!! urgh thanks

Didnt click thats how we join variables to strings in VB.
Glad to help!