Wrox Home  
Search P2P Archive for: Go

  Return to Index  

asp_databases thread: passing variables to SQL statement


Message #1 by "hal froot" <hfroot@a...> on Thu, 26 Sep 2002 21:41:22
I am trying to pass the value of strSignup to the SET parm of the SQL 
statement. I have used:
'"&strstrSignup&"' and strSignup both give me an error of no value for 
variable. I the other variables that I am passing in work fine. I have 
tested the variable to insure there is actually a value being passed to 
the page with the response.write statement. Any help would be appreciated.


Dim objComm, intNoOfRecords,strSignup,strMyname,strMyWeek
strMyWeek=request.form("MyWeek")
strMyname=request.form("Myname")
strSignup=request.form("hiddenrole")
response.write strSignup	& "<BR>"	
response.write strMyname	& "<BR>" 
response.write strMyweek	& "<BR>" 
Set objComm=Server.CreateObject("ADODB.Command")
objComm.ActiveConnection=strConnect
objComm.CommandText="UPDATE name SET Toastmaster= '"&strMyname&"' " &_
		"WHERE week ='"&strMyWeek&"'"
Message #2 by "Peter Foti (PeterF)" <PeterF@S...> on Thu, 26 Sep 2002 17:01:37 -0400
You might encounter a problem if strSignup contains a single quote.  You
should escape the single quotes by doing something like this:

<%
Function sql_quote(str)
   str = Replace(str,"'","''")
   sql_quote = "'"& str & "'"
End Function

Dim objComm, intNoOfRecords,strSignup,strMyname,strMyWeek
strMyWeek = Trim(CStr(Request.form("MyWeek")))
strMyname = Trim(CStr(Request.form("Myname")))
strSignup = Trim(CStr(Request.form("hiddenrole")))
Response.Write strSignup	& "<BR>"	
Response.Write strMyname	& "<BR>" 
Response.Write strMyweek	& "<BR>" 
Set objComm = Server.CreateObject("ADODB.Command")
objComm.ActiveConnection = strConnect
objComm.CommandText = "UPDATE name " & _
		" SET Toastmaster=" & sql_quote(strMyname) & _
		", Signup=" & sql_quote(strSignup) & _
		" WHERE week=" & sql_quote(strMyWeek)

This assumes that the field name is Signup.
Hope this helps.
Pete




> -----Original Message-----
> From: hal froot [mailto:hfroot@a...]
> Sent: Thursday, September 26, 2002 9:41 PM
> To: ASP Databases
> Subject: [asp_databases] passing variables to SQL statement
> 
> 
> I am trying to pass the value of strSignup to the SET parm of the SQL 
> statement. I have used:
> '"&strstrSignup&"' and strSignup both give me an error of no 
> value for 
> variable. I the other variables that I am passing in work 
> fine. I have 
> tested the variable to insure there is actually a value being 
> passed to 
> the page with the response.write statement. Any help would be 
> appreciated.
> 
> 
> Dim objComm, intNoOfRecords,strSignup,strMyname,strMyWeek
> strMyWeek=request.form("MyWeek")
> strMyname=request.form("Myname")
> strSignup=request.form("hiddenrole")
> response.write strSignup	& "<BR>"	
> response.write strMyname	& "<BR>" 
> response.write strMyweek	& "<BR>" 
> Set objComm=Server.CreateObject("ADODB.Command")
> objComm.ActiveConnection=strConnect
> objComm.CommandText="UPDATE name SET Toastmaster= '"&strMyname&"' " &_
> 		"WHERE week ='"&strMyWeek&"'"
> 

  Return to Index