Reply to topic
Updating a Database Problem
apexonelove


Joined: 30 Mar 2005
Posts: 7
Location: Utah
Reply with quote
I'm not really sure what's going on with my code here. It seems like I've done everything right (as far as DreamWeaver is concerned)....but I get a:

Microsoft OLE DB Provider for ODBC Drivers error '80040e14'
[Microsoft][ODBC Microsoft Access Driver] Syntax error in UPDATE statement.
/norry/detailededit.asp, line 111

this is my code:





<%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
<!--#include file="Connections/norryconn.asp" -->
<%
' *** Edit Operations: declare variables

Dim MM_editAction
Dim MM_abortEdit
Dim MM_editQuery
Dim MM_editCmd

Dim MM_editConnection
Dim MM_editTable
Dim MM_editRedirectUrl
Dim MM_editColumn
Dim MM_recordId

Dim MM_fieldsStr
Dim MM_columnsStr
Dim MM_fields
Dim MM_columns
Dim MM_typeArray
Dim MM_formVal
Dim MM_delim
Dim MM_altVal
Dim MM_emptyVal
Dim MM_i

MM_editAction = CStr(Request.ServerVariables("SCRIPT_NAME"))
If (Request.QueryString <> "") Then
MM_editAction = MM_editAction & "?" & Server.HTMLEncode(Request.QueryString)
End If

' boolean to abort record edit
MM_abortEdit = false

' query string to execute
MM_editQuery = ""
%>
<%
' *** Update Record: set variables

If (CStr(Request("MM_update")) = "updater" And CStr(Request("MM_recordId")) <> "") Then

MM_editConnection = MM_norryconn_STRING
MM_editTable = "tblProp"
MM_editColumn = "ID"
MM_recordId = "" + Request.Form("MM_recordId") + ""
MM_editRedirectUrl = "plisting.asp"
MM_fieldsStr = "textfield|value|textarea|value|parking|value|zoned|value|sqft|value|sqftavail|value|priceper|value|ceiling|value|loadingdocks|value|city|value|state|value|zip|value|salesrep|value"
MM_columnsStr = "PropName|',none,''|Desc|',none,''|parking|',none,''|zoning|',none,''|buildingsq|',none,''|availsq|',none,''|pricepersq|',none,''|Ceilingheight|',none,''|Loadingdocks|',none,''|City|',none,''|State|',none,''|Zip|',none,''|contactinfo|',none,''"

' create the MM_fields and MM_columns arrays
MM_fields = Split(MM_fieldsStr, "|")
MM_columns = Split(MM_columnsStr, "|")

' set the form values
For MM_i = LBound(MM_fields) To UBound(MM_fields) Step 2
MM_fields(MM_i+1) = CStr(Request.Form(MM_fields(MM_i)))
Next

' append the query string to the redirect URL
If (MM_editRedirectUrl <> "" And Request.QueryString <> "") Then
If (InStr(1, MM_editRedirectUrl, "?", vbTextCompare) = 0 And Request.QueryString <> "") Then
MM_editRedirectUrl = MM_editRedirectUrl & "?" & Request.QueryString
Else
MM_editRedirectUrl = MM_editRedirectUrl & "&" & Request.QueryString
End If
End If

End If
%>
<%
' *** Update Record: construct a sql update statement and execute it

If (CStr(Request("MM_update")) <> "" And CStr(Request("MM_recordId")) <> "") Then

' create the sql update statement
MM_editQuery = "update " & MM_editTable & " set "
For MM_i = LBound(MM_fields) To UBound(MM_fields) Step 2
MM_formVal = MM_fields(MM_i+1)
MM_typeArray = Split(MM_columns(MM_i+1),",")
MM_delim = MM_typeArray(0)
If (MM_delim = "none") Then MM_delim = ""
MM_altVal = MM_typeArray(1)
If (MM_altVal = "none") Then MM_altVal = ""
MM_emptyVal = MM_typeArray(2)
If (MM_emptyVal = "none") Then MM_emptyVal = ""
If (MM_formVal = "") Then
MM_formVal = MM_emptyVal
Else
If (MM_altVal <> "") Then
MM_formVal = MM_altVal
ElseIf (MM_delim = "'") Then ' escape quotes
MM_formVal = "'" & Replace(MM_formVal,"'","''") & "'"
Else
MM_formVal = MM_delim + MM_formVal + MM_delim
End If
End If
If (MM_i <> LBound(MM_fields)) Then
MM_editQuery = MM_editQuery & ","
End If
MM_editQuery = MM_editQuery & MM_columns(MM_i) & " = " & MM_formVal
Next
MM_editQuery = MM_editQuery & " where " & MM_editColumn & " = " & MM_recordId

If (Not MM_abortEdit) Then
' execute the update
Set MM_editCmd = Server.CreateObject("ADODB.Command")
MM_editCmd.ActiveConnection = MM_editConnection
MM_editCmd.CommandText = MM_editQuery
MM_editCmd.Execute
MM_editCmd.ActiveConnection.Close

If (MM_editRedirectUrl <> "") Then
Response.Redirect(MM_editRedirectUrl)
End If
End If

End If
%>
<%
Dim detailedit__MMColParam
detailedit__MMColParam = "1"
If (Request.QueryString("ID") <> "") Then
detailedit__MMColParam = Request.QueryString("ID")
End If
%>
<%
Dim detailedit
Dim detailedit_numRows

Set detailedit = Server.CreateObject("ADODB.Recordset")
detailedit.ActiveConnection = MM_norryconn_STRING
detailedit.Source = "SELECT * FROM tblProp WHERE ID = " + Replace(detailedit__MMColParam, "'", "''") + ""
detailedit.CursorType = 0
detailedit.CursorLocation = 2
detailedit.LockType = 1
detailedit.Open()

detailedit_numRows = 0
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link href="norrystyle.css" rel="stylesheet" type="text/css">
<style type="text/css">
<!--
.style1 {font-size: 14px}
-->
</style>
</head>

<body><form action="<%=MM_editAction%>" method="POST" name="updater" id="updater"><table width="95%" border="0" cellpadding="4" cellspacing="2">
<tr>
<td class="norrystyle">Property ID: </td>
<td class="norrystyle"><input name="textfield2" type="text" class="norrystyle" value="<%=(detailedit.Fields.Item("ID").Value)%>" size="10"></td>
</tr>
<tr>
<td width="22%" class="norrystyle">Property Name:</td>
<td width="78%" class="norrystyle">
<input name="textfield" type="text" class="norrystyle" value="<%=(detailedit.Fields.Item("PropName").Value)%>" size="40"></td>
</tr>
<tr>
<td class="norrystyle">Property Description:</td>
<td width="78%" class="norrystyle">
<textarea name="textarea" cols="60" rows="6" class="norrystyle"><%=(detailedit.Fields.Item("Desc").Value)%></textarea></td>
</tr>
<tr>
<td height="27" class="norrystyle">Parking: <br></td>
<td width="78%" class="norrystyle"><input name="parking" type="text" class="norrystyle" id="parking" value="<%=(detailedit.Fields.Item("parking").Value)%>"></td>
</tr>
<tr>
<td class="norrystyle">Zoned for: </td>
<td width="78%" class="norrystyle"><input name="zoned" type="text" class="norrystyle" id="zoned" value="<%=(detailedit.Fields.Item("zoning").Value)%>" size="30"></td>
</tr>
<tr>
<td class="norrystyle">Building Square Footage: <br></td>
<td width="78%" class="norrystyle"><input name="sqft" type="text" class="norrystyle" id="sqft" value="<%=(detailedit.Fields.Item("buildingsq").Value)%>"></td>
</tr>
<tr>
<td class="norrystyle">Square Feet Available:<br></td>
<td width="78%" class="norrystyle"><input name="sqftavail" type="text" class="norrystyle" id="sqftavail" value="<%=(detailedit.Fields.Item("availsq").Value)%>"></td>
</tr>
<tr>
<td class="norrystyle">Price Per Square Foot: <br></td>
<td width="78%" class="norrystyle"><input name="priceper" type="text" class="norrystyle" id="priceper" value="<%=(detailedit.Fields.Item("pricepersq").Value)%>"></td>
</tr>
<tr>
<td class="norrystyle">Date Available: <br></td>
<td width="78%" class="norrystyle"><input name="dateavail" type="text" class="norrystyle" id="dateavail" value="<%=(detailedit.Fields.Item("Available Date").Value)%>"></td>
</tr>
<tr>
<td class="norrystyle">Ceiling Height: <br></td>
<td width="78%" class="norrystyle"><input name="ceiling" type="text" class="norrystyle" id="ceiling" value="<%=(detailedit.Fields.Item("Ceilingheight").Value)%>"></td>
</tr>
<tr>
<td class="norrystyle">Loading Docks:</td>
<td width="78%" class="norrystyle"><input name="loadingdocks" type="text" class="norrystyle" id="loadingdocks" value="<%=(detailedit.Fields.Item("Loadingdocks").Value)%>"></td>
</tr>
<tr>
<td class="norrystyle">City:</td>
<td class="norrystyle"><input name="city" type="text" class="norrystyle" id="city" value="<%=(detailedit.Fields.Item("City").Value)%>"></td>
</tr>
<tr>
<td class="norrystyle">State:</td>
<td class="norrystyle"><input name="state" type="text" class="norrystyle" id="state" value="<%=(detailedit.Fields.Item("State").Value)%>"></td>
</tr>
<tr>
<td class="norrystyle">Zip:</td>
<td class="norrystyle"><input name="zip" type="text" class="norrystyle" id="zip" value="<%=(detailedit.Fields.Item("Zip").Value)%>" size="15"></td>
</tr>
<tr>
<td height="39" class="norrystyle">Contact Sales Representative: </td>
<td class="norrystyle"><input name="salesrep" type="text" class="norrystyle" id="salesrep" value="<%=(detailedit.Fields.Item("contactinfo").Value)%>" size="50"></td>
</tr>
<tr>
<td colspan="2" class="norrystyle">
<input name="update" type="submit" class="norrygreenline" id="update" value="Update Property">
</td>
</tr>
</table>
<input type="hidden" name="MM_update" value="updater">
<input type="hidden" name="MM_recordId" value="<%= detailedit.Fields.Item("ID").Value %>">
</form>

</body>
</html>
<%
detailedit.Close()
Set detailedit = Nothing
%>
Josh
Forum Regular

Joined: 01 Apr 2004
Posts: 1029
Location: Felton, Delaware
Reply with quote
Do you have write/modify permissions enabled on the MDB file residing on the server? If not, or you're not sure, email support@hostmysite.com and request to have those permissions added to the folder where the Access DB resides.
Josh
Forum Regular

Joined: 01 Apr 2004
Posts: 1029
Location: Felton, Delaware
Reply with quote
Oh I just realized this said syntax error... try this... before you actually execute the command, try just doing a response.write of the query string and see if you can pinpoint where your problem is. You may want to look into using parameterized queries instead of a long concatinated string also... it'll make things ALOT easier.
apexonelove


Joined: 30 Mar 2005
Posts: 7
Location: Utah
Reply with quote
Josh, thanks so much for your help on this one man, I really appreciate it. I'm not too too savvy on how to make that change though, I'm new to the whole .Asp game and just use Dreamweaver...I guess they're the one's to blame on this one! ha....

It weird, because I've tried doing the update on just 1 field, and it works beautifully, but it doesn't like it when there is more that 1 field that it needs to update. Would that be resolved with a response.write query string? Is there a good source where I can look to figure out how to do that? Also, could it be the way i setup my form?


Thanks so much, again,

-Jonathan
apexonelove


Joined: 30 Mar 2005
Posts: 7
Location: Utah
Reply with quote
This is the update record block, wherein the SYNTAX ERROR resides.

<%
' *** Update Record: construct a sql update statement and execute it

If (CStr(Request("MM_update")) <> "" And CStr(Request("MM_recordId")) <> "") Then

' create the sql update statement
MM_editQuery = "update " & MM_editTable & " set "
For MM_i = LBound(MM_fields) To UBound(MM_fields) Step 2
MM_formVal = MM_fields(MM_i+1)
MM_typeArray = Split(MM_columns(MM_i+1),",")
MM_delim = MM_typeArray(0)
If (MM_delim = "none") Then MM_delim = ""
MM_altVal = MM_typeArray(1)
If (MM_altVal = "none") Then MM_altVal = ""
MM_emptyVal = MM_typeArray(2)
If (MM_emptyVal = "none") Then MM_emptyVal = ""
If (MM_formVal = "") Then
MM_formVal = MM_emptyVal
Else
If (MM_altVal <> "") Then
MM_formVal = MM_altVal
ElseIf (MM_delim = "'") Then ' escape quotes
MM_formVal = "'" & Replace(MM_formVal,"'","''") & "'"
Else
MM_formVal = MM_delim + MM_formVal + MM_delim
End If
End If
If (MM_i <> LBound(MM_fields)) Then
MM_editQuery = MM_editQuery & ","
End If
MM_editQuery = MM_editQuery & MM_columns(MM_i) & " = " & MM_formVal
Next
MM_editQuery = MM_editQuery & " where " & MM_editColumn & " = " & MM_recordId

If (Not MM_abortEdit) Then
' execute the update
Set MM_editCmd = Server.CreateObject("ADODB.Command")
MM_editCmd.ActiveConnection = MM_editConnection
MM_editCmd.CommandText = MM_editQuery
MM_editCmd.Execute
MM_editCmd.ActiveConnection.Close

If (MM_editRedirectUrl <> "") Then
Response.Redirect(MM_editRedirectUrl)
End If
End If

End If
%>




This is the same section, but with only 1 field...and the string working:

<%
' *** Update Record: construct a sql update statement and execute it

If (CStr(Request("MM_update")) <> "" And CStr(Request("MM_recordId")) <> "") Then

' create the sql update statement
MM_editQuery = "update " & MM_editTable & " set "
For MM_i = LBound(MM_fields) To UBound(MM_fields) Step 2
MM_formVal = MM_fields(MM_i+1)
MM_typeArray = Split(MM_columns(MM_i+1),",")
MM_delim = MM_typeArray(0)
If (MM_delim = "none") Then MM_delim = ""
MM_altVal = MM_typeArray(1)
If (MM_altVal = "none") Then MM_altVal = ""
MM_emptyVal = MM_typeArray(2)
If (MM_emptyVal = "none") Then MM_emptyVal = ""
If (MM_formVal = "") Then
MM_formVal = MM_emptyVal
Else
If (MM_altVal <> "") Then
MM_formVal = MM_altVal
ElseIf (MM_delim = "'") Then ' escape quotes
MM_formVal = "'" & Replace(MM_formVal,"'","''") & "'"
Else
MM_formVal = MM_delim + MM_formVal + MM_delim
End If
End If
If (MM_i <> LBound(MM_fields)) Then
MM_editQuery = MM_editQuery & ","
End If
MM_editQuery = MM_editQuery & MM_columns(MM_i) & " = " & MM_formVal
Next
MM_editQuery = MM_editQuery & " where " & MM_editColumn & " = " & MM_recordId

If (Not MM_abortEdit) Then
' execute the update
Set MM_editCmd = Server.CreateObject("ADODB.Command")
MM_editCmd.ActiveConnection = MM_editConnection
MM_editCmd.CommandText = MM_editQuery
MM_editCmd.Execute
MM_editCmd.ActiveConnection.Close

If (MM_editRedirectUrl <> "") Then
Response.Redirect(MM_editRedirectUrl)
End If
End If

End If
%>



thanks os much..you guys rock.
Josh
Forum Regular

Joined: 01 Apr 2004
Posts: 1029
Location: Felton, Delaware
Reply with quote
apex use this...

Code:
<%
' *** Update Record: construct a sql update statement and execute it

If (CStr(Request("MM_update")) <> "" And CStr(Request("MM_recordId")) <> "") Then

   ' create the sql update statement
   MM_editQuery = "update " & MM_editTable & " set "
   For MM_i = LBound(MM_fields) To UBound(MM_fields) Step 2
      MM_formVal = MM_fields(MM_i+1)
      MM_typeArray = Split(MM_columns(MM_i+1),",")
      MM_delim = MM_typeArray(0)
      If (MM_delim = "none") Then MM_delim = ""
         MM_altVal = MM_typeArray(1)
            If (MM_altVal = "none") Then MM_altVal = ""
            MM_emptyVal = MM_typeArray(2)
               If (MM_emptyVal = "none") Then MM_emptyVal = ""
                  If (MM_formVal = "") Then
                     MM_formVal = MM_emptyVal
                  Else
                     If (MM_altVal <> "") Then
                        MM_formVal = MM_altVal
                     ElseIf (MM_delim = "'") Then ' escape quotes
                        MM_formVal = "'" & Replace(MM_formVal,"'","''") & "'"
                     Else
                        MM_formVal = MM_delim + MM_formVal + MM_delim
                     End If
                  End If
               End If
         If (MM_i <> LBound(MM_fields)) Then
         MM_editQuery = MM_editQuery & ","
         End If
      MM_editQuery = MM_editQuery & MM_columns(MM_i) & " = " & MM_formVal
   Next
   MM_editQuery = MM_editQuery & " where " & MM_editColumn & " = " & MM_recordId
   
   If (Not MM_abortEdit) Then
      Response.Write MM_editQuery
      
      'everything else below here is commented.  This will enable the query string
      '(MM_editQuery) to be shown in the browser window so you can check your
      'syntax and determine where the problem is in the query/command.
      '
      'When you've fixed what's causing the issue, you can then unremark/uncomment
      'all of the code below and delete this comment block.
      '
      ' execute the update
      'Set MM_editCmd = Server.CreateObject("ADODB.Command")
      'MM_editCmd.ActiveConnection = MM_editConnection
      'MM_editCmd.CommandText = MM_editQuery
      'MM_editCmd.Execute
      'MM_editCmd.ActiveConnection.Close
      '
      'If (MM_editRedirectUrl <> "") Then Response.Redirect(MM_editRedirectUrl)
   End If

End If

%>
apexonelove


Joined: 30 Mar 2005
Posts: 7
Location: Utah
Reply with quote
Might my problem be that I don't have SQL support with my current plan? I've got .asp, but they told me it's just supported for access databases.
Josh
Forum Regular

Joined: 01 Apr 2004
Posts: 1029
Location: Felton, Delaware
Reply with quote
No... see, you use the T-SQL language to communicate with the Access database. How much do you know about what you're doing?
apexonelove


Joined: 30 Mar 2005
Posts: 7
Location: Utah
Reply with quote
not much, just enought dreamweaver to usually get by, but this one's being tricky.
Josh
Forum Regular

Joined: 01 Apr 2004
Posts: 1029
Location: Felton, Delaware
Reply with quote
Okay... that's why all that MM created code is in there... I can think of easier ways to accomplish this, but I'm afraid that I'd probably confuse you as well... it's a tough spot. Your problem is more than likely caused by trying to insert data into the DB that "doesn't match up" with the field type used. Like trying to insert data into a DateTime field, but not first converting it to a string (for Access - not anything else).

Did you use that code I posted? What it should have done is returned a SQL Statement, like "UPDATE TableName SET FieldName=Value"... did it? Would you mind posting what was displayed?
bobum
Elvis Fanatic
Elvis Fanatic

Joined: 16 Nov 2004
Posts: 746
Location: Montgomery, AL
Reply with quote
THe REsponse.Write that Josh is talking about won't fix any problem - it's just going to output the actual databasse command that is giving you the error.

Once we see that command, I imagine the next thing we'll need will be the database schema to make sure that the SQL COmmand and the DB line up correctly, unless there is a blatent SQL command that's being made.

Usually DW is pretty good about doing this stuff - but occasionally it needs a bit of help especially if you are doing multiple things on one pae, it tends to step all over itself when it's auto generating the code.
degsy


Joined: 11 Jul 2005
Posts: 2
Reply with quote
I've found a temporary fix for this problem.

Code:

MM_columnsStr = "PropName|',none,''|Desc|',none,''|parking|',none,''|zoning|',none,''|buildingsq|',none,''|availsq|',none,''|pricepersq|',none,''|Ceilingheight|',none,''|Loadingdocks|',none,''|City|',none,''|State|',none,''|Zip|',none,''|contactinfo|',none,''"

Add square brackets to the field names

Code:

MM_columnsStr = "[PropName]|',none,''|[Desc]|',none,''|[parking]|',none,''...

Problem is that if you open the query again from the DW Application menu then it will reset it/remove the brackets.

I suppose you could add a custom function where DW splits the string to add the brackets back in.

Cheers,
Degs
degsy


Joined: 11 Jul 2005
Posts: 2
Reply with quote
or edit the query line to
Code:

MM_editQuery = MM_editQuery & "[" & MM_columns(MM_i) & "]" & " = " & MM_formVal


Haven't tried this but you should also be able to permenantly alter it be editing the updateRecord_query.edml file in the \Configuration\ServerBehaviors\ASP_Vbs folder
Updating a Database Problem
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
All times are GMT  
Page 1 of 1  

  
  
 Reply to topic