Wrox Programmer Forums
|
Classic ASP Databases Discuss using ASP 3 to work with data in databases, including ASP Database Setup issues from the old P2P forum on this specific subtopic. See also the book forum Beginning ASP.NET Databases for questions specific to that book. NOT for ASP.NET 1.0, 1.1, or 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Classic ASP Databases section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old May 1st, 2012, 11:56 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 196
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to jmss66
Default syntax error in update statement

I am trying to update several fields in a record. I tried updating just one field and it works. If i update more than one field then I get the message Syntax Error in Update statement.
I had to rewrite my code to using a prepared statement. I was using ADO and it was working fine. Please help me figure out why I am having a syntax error if I am upding more than one field. Thanks. Below is my code:
Code:
 Set objCmd = Server.CreateObject("ADODB.command")
 objCmd.ActiveConnection = objConn
 If blnNewRecord Then
  objCmd.CommandText = "INSERT INTO Member SET EmailAddress = ?, Password = ?, FamilyName = ?, GivenName = ?, PhoneNumber = ?, StreetAddress1 = ?, "
  If Session("StreetAddress2") <> " " Then
   objCmd.CommandText = objCmd.CommandText & "StreetAddress2 = ?, City = ?, State = ?, PostalCode = ?, Country = ?, "
  Else
   objCmd.CommandText = objCmd.CommandText & "City = ?, State = ?, PostalCode = ?, Country = ?, "
  End If
  objCmd.CommandText = objCmd.CommandText & "Active = ?, LastLogin = ?, RegistrationDate = ?, MailingList = ?, Status = ? WHERE SSN = ? "
 Else
   objCmd.CommandText = "UPDATE Member SET EmailAddress = ?, Password = ?, FamilyName = ?, GivenName = ?, PhoneNumber = ?, StreetAddress1 = ?, "
   If Session("StreetAddress2") <> "" Then
    objCmd.CommandText = objCmd.CommandText & "StreetAddress2 = ?, City = ?, State = ?, PostalCode = ?, Country = ?, "
   Else
    objCmd.CommandText = objCmd.CommandText & "City = ?, State = ?, PostalCode = ?, Country = ?, "
   End If
    objCmd.CommandText = objCmd.CommandText & "Active = ?, LastLogin = ?, RegistrationDate = ?, MailingList = ?, Status = ? WHERE SSN = ? "
 End If
 objCmd.CommandType = adCmdText
 objCmd.Prepared = True
 objCmd.Parameters.Append(objCmd.CreateParameter("EMailAddress", adVarChar, adParamInput, Len(Request("Email")), Request("EMail")))
 objCmd.Parameters.Append(objCmd.CreateParameter("Password", adChar, adParamInput, Len(Request("Password")), Request("Password")))
 objCmd.Parameters.Append(objCmd.CreateParameter("FamilyName", adChar, adParamInput, Len(Request("FamilyName")), Request("FamilyName")))
 objCmd.Parameters.Append(objCmd.CreateParameter("GivenName", adChar, adParamInput, Len(Request("GivenName")), Request("GivenName")))
 objCmd.Parameters.Append(objCmd.CreateParameter("PhoneNumber", adChar, adParamInput, Len(Request("PhoneNumber")), Request("PhoneNumber")))
 objCmd.Parameters.Append(objCmd.CreateParameter("StreetAddress1", adChar, adParamInput, Len(Request("Address1")), Request("Address1")))
 If Request("StreetAddress2") <> "" Then
  objCmd.Parameters.Append(objCmd.CreateParameter("StreetAddress2", adChar, adParamInput, Len(Request("Address2")), Request("Address2")))
 End If
 objCmd.Parameters.Append(objCmd.CreateParameter("City", adChar, adParamInput, Len(Request("City")), Request("City")))
 objCmd.Parameters.Append(objCmd.CreateParameter("State", adChar, adParamInput, Len(Request("State")), Request("State")))
 objCmd.Parameters.Append(objCmd.CreateParameter("PostalCode", adChar, adParamInput, Len(Request("PostalCode")), Request("PostalCode")))
 objCmd.Parameters.Append(objCmd.CreateParameter("Country", adChar, adParamInput, Len(Request("Country")), Request("Country")))
 objCmd.Parameters.Append(objCmd.CreateParameter("Active", adBoolean, adParamInput, Len(Request("Active")), TRUE))
 objCmd.Parameters.Append(objCmd.CreateParameter("LastLogin", adDate, adParamInput, Len(Now()), Now()))
 objCmd.Parameters.Append(objCmd.CreateParameter("RegistrationDate", adDate, adParamInput, Len(Request("RegistrationDate")), Request("RegistrationDate")))
 If Request("MailingList") = Checked Then
  objCmd.Parameters.Append(objCmd.CreateParameter("MailingList", adBoolean, adParamInput, Len(MailingList), TRUE))
 Else
  objCmd.Parameters.Append(objCmd.CreateParameter("MailingList", adBoolean, adParamInput, Len(MailingList), FALSE))
 End If
 objCmd.Parameters.Append(objCmd.CreateParameter("Status", adChar, adParamInput, Len(rsMemInfo("Status")), rsMemInfo("Status")))
 objCmd.Parameters.Append(objCmd.CreateParameter("SSN", adInteger, adParamInput, Len(Session("SSN")), Session("SSN")))





Similar Threads
Thread Thread Starter Forum Replies Last Post
syntax error in update statement Yasho .NET Framework 1.x 2 September 10th, 2010 04:13 PM
NEED HELP INSERT INTO statement syntax error koco ASP.NET 1.0 and 1.1 Basics 6 June 2nd, 2006 04:01 PM
Syntax error in INSERT INTO statement. kingleon Classic ASP Basics 1 May 10th, 2005 06:25 PM
Syntax Error in the update statement annie_t Access ASP 1 February 1st, 2005 12:48 PM
UPDATE statement returns syntax error AviatorTim Classic ASP Databases 2 January 8th, 2004 05:22 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.