Search code examples
sqlasp-classic

How to use ASP variables in SQL statement


<%
postit = request.querystring("thispost")
response.write(postit)
%> 

postit is the variable. The response.write works and this is all above the SQL statement below.

This is the SQL however when I add the postit variable I get this error message:

delCmd.CommandText="DELETE * FROM post WHERE (pos_ID = postit )"
Microsoft Access Database Engine error '80040e10'
No value given for one or more required parameters. 
/student/s0190204/wip/deleterecord.asp, line 32

Solution

  • Add a parameter to the SQL:

    delCmd.CommandText="DELETE * FROM post WHERE (pos_ID = ?)"
    delCmd.Parameters.Append delCmd.CreateParameter("posid", adInteger, adParamInput)   ' input parameter
    delCmd.Parameters("posid").Value = postit