Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old May 1st, 2012, 11:56 AM
Friend of Wrox
Points: 1,035, Level: 12
Points: 1,035, Level: 12 Points: 1,035, Level: 12 Points: 1,035, Level: 12
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: , , USA.
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")))
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 04:37 AM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.