Wrox Home  
Search P2P Archive for: Go

  Return to Index  

access_asp thread: Please HELP with Update statement


Message #1 by "NAJ" <noni_j@h...> on Wed, 9 Oct 2002 21:23:46
Hello I'm a newbie with ASP and I am having some trouble with my UPDATE 
stmt.  I adopted my update stmt from the example in the book 
titled "Beginning ASP Databases".  The star by the code denotes my update 
stmts.  I am getting this error:  Too few parameters.  Expected 1.  Here 
is my sql stmt I used to pull the info from the database:

sqltext="Select * FROM Employees INNER JOIN FutureCurve"
sqltext=sqltext & " ON Employees.EmployeeID=FutureCurve.EmployeeID"
sqltext=sqltext & " WHERE Employees.EmployeeID='" & varEmployeeID & "';"


Here is my UPDATE code:

'Start building the SQL string
	strSQL = "Update FutureCurve Set" *************HERE 
	
	'Set the first parameter flag to true
	blnFirstParameter = True
		
	'Update Question 1 if present
	If Len(Request.Form("txtQuestion1")) > 0 Then
		'Add the value to the SQL string
		strSQL = strSQL & " Question1 = '" & _
			Cstr(Request.Form("txtQuestion1")) & "'"
		'Set the first parameter flag to false
		blnFirstParameter = False
	End If
	
	'Update Question 2 if present
	If Len(Request.Form("txtQuestion2")) > 0 Then
		'Add the value to the SQL string
		If blnFirstParameter Then
			strSQL = strSQL & " Question2 = '" 
		Else
			strSQL = strSQL & ", Question2 = '" 
		End If
		strSQL = strSQL &	Cstr(Request.Form("txtQuestion2")) 
& "'"
		'Set the first parameter flag to false
		blnFirstParameter = False
	End If
	
	'Update Question 3 if present
	If Len(Request.Form("txtQuestion3")) > 0 Then
		'Add the value to the SQL string
		If blnFirstParameter Then
			strSQL = strSQL & " Question3 = '" 
		Else
			strSQL = strSQL & ", Question3 = '" 
		End If
		strSQL = strSQL &	Cstr(Request.Form("txtQuestion3")) 
& "'"
		'Set the first parameter flag to false
		blnFirstParameter = False
	End If
	
	'Update Question 4 if present
	If Len(Request.Form("txtQuestion4")) > 0 Then
		'Add the value to the SQL string
		If blnFirstParameter Then
			strSQL = strSQL & " Question4 = '" 
		Else
			strSQL = strSQL & ", Question4 = '" 
		End If
		strSQL = strSQL &	Cstr(Request.Form("txtQuestion4")) 
& "'"
		'Set the first parameter flag to false
		blnFirstParameter = False
	End If
	
	'Update Question 5 if present
	If Len(Request.Form("txtQuestion5")) > 0 Then
		'Add the value to the SQL string
		If blnFirstParameter Then
			strSQL = strSQL & " Question5 = '" 
		Else
			strSQL = strSQL & ", Question5 = '" 
		End If
		strSQL = strSQL &	Cstr(Request.Form("txtQuestion5")) 
& "'"
		'Set the first parameter flag to false
		blnFirstParameter = False
	End If

	'Update Question 6 if present
	If Len(Request.Form("txtQuestion6")) > 0 Then
		'Add the value to the SQL string
		If blnFirstParameter Then
			strSQL = strSQL & " Question6 = '" 
		Else
			strSQL = strSQL & ", Question6 = '" 
		End If
		strSQL = strSQL &	Cstr(Request.Form("txtQuestion6")) 
& "'"
		'Set the first parameter flag to false
		blnFirstParameter = False
	End If

	'Set the Where clause
	strSQL= strSQL & " WHERE Employees.EmployeeID='" & varEmployeeID 
& "';" *****************& HERE
	
	'Create and open the database object
	Set objConn = Server.CreateObject("ADODB.Connection")
	objConn.Open "DSN=noni"

	'Create the command object
	Set objCmd = Server.CreateObject("ADODB.Command")

	'Set the command object properties
	Set objCmd.ActiveConnection = objConn
	objCmd.CommandText = strSQL
	objCmd.CommandType = adCmdText

	'Execute the command
	objCmd.Execute

	'Display the update string
	Response.Write "The following update string was executed and " & _
		"the values updated in the FutureCurve table.<P>"
	Response.Write strSQL 

End If


'Close and dereference database objects
Set objCmd = Nothing
objConn.Close
Set objConn = Nothing


PLEASE HELP!!!!!!!!!!!!!!!

Thanx, Newbie
Message #2 by "Shawn Clabough" <shawnc@u...> on Thu, 10 Oct 2002 00:52:29
If you response.write the strSQL variable to the screen just before you 
execute it, I think you'll find that you're referring to a field that 
does not exist in the database tables you're querying from.  If you're 
still stuck, reply to the list with the actual SQL statement it displays 
as well as the list of fields in the database.

Shawn

> Hello I'm a newbie with ASP and I am having some trouble with my UPDATE 
s> tmt.  I adopted my update stmt from the example in the book 
t> itled "Beginning ASP Databases".  The star by the code denotes my 
update 
s> tmts.  I am getting this error:  Too few parameters.  Expected 1.  
Here 
i> s my sql stmt I used to pull the info from the database:

> sqltext="Select * FROM Employees INNER JOIN FutureCurve"
s> qltext=sqltext & " ON Employees.EmployeeID=FutureCurve.EmployeeID"
s> qltext=sqltext & " WHERE Employees.EmployeeID='" & varEmployeeID & "';"

> 
H> ere is my UPDATE code:

> 'Start building the SQL string
	> strSQL = "Update FutureCurve Set" *************HERE 
	> 
	> 'Set the first parameter flag to true
	> blnFirstParameter = True
	> 	
	> 'Update Question 1 if present
	> If Len(Request.Form("txtQuestion1")) > 0 Then
	> 	'Add the value to the SQL string
	> 	strSQL = strSQL & " Question1 = '" & _
	> 		Cstr(Request.Form("txtQuestion1")) & "'"
	> 	'Set the first parameter flag to false
	> 	blnFirstParameter = False
	> End If
	> 
	> 'Update Question 2 if present
	> If Len(Request.Form("txtQuestion2")) > 0 Then
	> 	'Add the value to the SQL string
	> 	If blnFirstParameter Then
	> 		strSQL = strSQL & " Question2 = '" 
	> 	Else
	> 		strSQL = strSQL & ", Question2 = '" 
	> 	End If
	> 	strSQL = strSQL &	Cstr(Request.Form
("txtQuestion2")) 
&>  "'"
	> 	'Set the first parameter flag to false
	> 	blnFirstParameter = False
	> End If
	> 
	> 'Update Question 3 if present
	> If Len(Request.Form("txtQuestion3")) > 0 Then
	> 	'Add the value to the SQL string
	> 	If blnFirstParameter Then
	> 		strSQL = strSQL & " Question3 = '" 
	> 	Else
	> 		strSQL = strSQL & ", Question3 = '" 
	> 	End If
	> 	strSQL = strSQL &	Cstr(Request.Form
("txtQuestion3")) 
&>  "'"
	> 	'Set the first parameter flag to false
	> 	blnFirstParameter = False
	> End If
	> 
	> 'Update Question 4 if present
	> If Len(Request.Form("txtQuestion4")) > 0 Then
	> 	'Add the value to the SQL string
	> 	If blnFirstParameter Then
	> 		strSQL = strSQL & " Question4 = '" 
	> 	Else
	> 		strSQL = strSQL & ", Question4 = '" 
	> 	End If
	> 	strSQL = strSQL &	Cstr(Request.Form
("txtQuestion4")) 
&>  "'"
	> 	'Set the first parameter flag to false
	> 	blnFirstParameter = False
	> End If
	> 
	> 'Update Question 5 if present
	> If Len(Request.Form("txtQuestion5")) > 0 Then
	> 	'Add the value to the SQL string
	> 	If blnFirstParameter Then
	> 		strSQL = strSQL & " Question5 = '" 
	> 	Else
	> 		strSQL = strSQL & ", Question5 = '" 
	> 	End If
	> 	strSQL = strSQL &	Cstr(Request.Form
("txtQuestion5")) 
&>  "'"
	> 	'Set the first parameter flag to false
	> 	blnFirstParameter = False
	> End If

> 	'Update Question 6 if present
	> If Len(Request.Form("txtQuestion6")) > 0 Then
	> 	'Add the value to the SQL string
	> 	If blnFirstParameter Then
	> 		strSQL = strSQL & " Question6 = '" 
	> 	Else
	> 		strSQL = strSQL & ", Question6 = '" 
	> 	End If
	> 	strSQL = strSQL &	Cstr(Request.Form
("txtQuestion6")) 
&>  "'"
	> 	'Set the first parameter flag to false
	> 	blnFirstParameter = False
	> End If

> 	'Set the Where clause
	> strSQL= strSQL & " WHERE Employees.EmployeeID='" & 
varEmployeeID 
&>  "';" *****************& HERE
	> 
	> 'Create and open the database object
	> Set objConn = Server.CreateObject("ADODB.Connection")
	> objConn.Open "DSN=noni"

> 	'Create the command object
	> Set objCmd = Server.CreateObject("ADODB.Command")

> 	'Set the command object properties
	> Set objCmd.ActiveConnection = objConn
	> objCmd.CommandText = strSQL
	> objCmd.CommandType = adCmdText

> 	'Execute the command
	> objCmd.Execute

> 	'Display the update string
	> Response.Write "The following update string was executed and " 
& _
	> 	"the values updated in the FutureCurve table.<P>"
	> Response.Write strSQL 

> End If

> 
'> Close and dereference database objects
S> et objCmd = Nothing
o> bjConn.Close
S> et objConn = Nothing

> 
P> LEASE HELP!!!!!!!!!!!!!!!

> Thanx, Newbie

  Return to Index