0

I'm not terribly familiar with asp, but I have one project with a page of it.

<% 
'declare the variables 
Dim Connection
Dim ConnString
Dim Recordset
Dim SQL
Dim userName 
userName = Request.Form("userName")
'define the connection string, specify database driver
ConnString="JJJJJ"//connection information

'declare the SQL statement that will query the database
SQL = "SELECT info AS Lunch, "
SQL = SQL & "FROM dbo.AgentActivityLog WHERE UserId = '" & userName & "'

'create an instance of the ADO connection and recordset objects
Set Connection = Server.CreateObject("ADODB.Connection")
Set Recordset = Server.CreateObject("ADODB.Recordset")

'Open the connection to the database
Connection.Open ConnString

'Open the recordset object executing the SQL statement and return records 
Recordset.Open SQL,Connection

'first of all determine whether there are any records 
If Recordset.EOF Then 
Response.Write("No records returned.") 
Else 
'process record
Next
Recordset.MoveNext     
Loop
End If

'close the connection and recordset objects to free up resources
Recordset.Close
Set Recordset=nothing
Connection.Close
Set Connection=nothing
%>

How do I parameterize the username? I have no way to debug, no knowledge of how this language works, so whatever I tried failed and I have no idea why.

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
user2430018
  • 121
  • 2
  • 5

1 Answers1

1

I would suggest you look at the Answer on following link as it will fill in the answers you seek: VBA, ADO.Connection and query parameters

From the code provided critical missing piece is the ADODB.Command for the SQL to actually be run and to add the parameter the query you would :

    Set Param = Command.CreateParameter("@userid",adVarChar,adParamInput)
    Param.Value = userName
    Command.Paramters.Append Param
Lynyrd
  • 76
  • 6
  • besides for changing the variable to a ?, and pasting in the code above, do I need to change my code further? The link looks completely different from the code I have. – user2430018 Apr 17 '20 at 13:23