troubleshooting Question

ASP and SQL varchar value to data type int error

Avatar of piemckay
piemckay asked on
ASPMicrosoft SQL Server 2005SQL
3 Comments1 Solution448 ViewsLast Modified:
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
%>

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?
ASKER CERTIFIED SOLUTION
Gerry Bartley
Software Engineer

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 3 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 3 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros