Solved

Record Update ASP conn.Execute sql

Posted on 2008-10-29
9
1,889 Views
Last Modified: 2013-12-07
For some reason it doesnt like my code:
I can Add and Delete Records from my table fine, but Update will n ot fly.
Any ideas?

Basically I am running the code that I revised based on the
http://www.w3schools.com/ADO/ado_update.asp

<html>
<body><h2>Update Record</h2>
 
<%
set conn=Server.CreateObject("ADODB.Connection")
conn.Provider="Microsoft.Jet.OLEDB.4.0"
conn.Open "D:\Performance Assurance Team\East_pmi.mdb"
 
cid=Request.Form("CAC")
 
if Request.form("Date Closed")="" then
  set rs=Server.CreateObject("ADODB.Recordset")
  rs.open "SELECT * FROM tblProactiveIssues WHERE CAC='" & cid & "'",conn
  %>
  <form method="post" action="RecordUpdate.asp">
  <table>
  <%for each x in rs.Fields%>
  <tr>
  <td><%=x.name%></td>
  <td><input name="<%=x.name%>" value="<%=x.value%>"></td>
  <%next%>
  </tr>
  </table>
  <br /><br />
  <input type="submit" value="Update record">
  </form>
<%
else
  sql="UPDATE tblProactiveIssues SET"
  sql=sql & "Region='" & Request.Form("Region") & "',"
  sql=sql & "Date Added='" & Request.Form("Date Added") & "',"
  sql=sql & "CAC='" & Request.Form("CAC") & "',"
  sql=sql & "CKTID='" & Request.Form("CKTID") & "',"
  sql=sql & "ACNA='" & Request.Form("ACNA") & "',"
  sql=sql & "Customer='" & Request.Form("Customer") & "',"
  sql=sql & "Ticket Number='" & Request.Form("Ticket Number") & "',"
  sql=sql & "Ticket Source='" & Request.Form("Ticket Source") & "',"
  sql=sql & "Monitoring Source='" & Request.Form("Monitoring Source") & "',"
  sql=sql & "Date Closed='" & Request.Form("Date Closed") & "',"
  sql=sql & "Disposition Code='" & Request.Form("Disposition Code") & "',"
  sql=sql & "Summary='" & Request.Form("Summary") & "'"
  sql=sql & " WHERE CAC='" & cid & "'"
  'on error resume next
   'conn.Execute sql
  if err<>0 then
    response.write("No update permissions!")
  else 
   Response.Redirect "View.asp" 
    'response.write("Record " & cid & " was updated!")
  end if 
end if
conn.close
%></body>
</html>

Open in new window

0
Comment
Question by:vzdog
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
  • 2
9 Comments
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 22833425
you have no space between SET and Region:
  sql="UPDATE tblProactiveIssues SET "
  sql=sql & " Region='" & Request.Form("Region") & "',"

Open in new window

0
 
LVL 82

Expert Comment

by:hielo
ID: 22833440
Do you get any runtime errors?

Also, I see:
"Date Added='" & Request.Form("Date Added") & "',"

is Date added a Date/Time Field? IF yes, then
 Request.Form("Date Added") needs to be in mm/dd/yyyy format

AND the value needs # instead of apostrophes:
"Date Added=#" & Request.Form("Date Added") & "#,"
0
 

Author Comment

by:vzdog
ID: 22836872
Some of my fields are numeric & alpha combined so is there something I should be using to indicate as such?
Date added is a date so how would I specify the format within the code?
0
Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

 
LVL 82

Expert Comment

by:hielo
ID: 22836913
numeric field values should NOT be enclosed in apostrophes
date field values  need to be enclosed in #
other values need to be enclosed in apostrophes
ex:

Update table Set aquisitionDate=#11/29/2008#, value=40000, condition='excellent' WHERE product_id=3
0
 

Author Comment

by:vzdog
ID: 22843412
What about when it is a combination of both in the same field?
ie:
PD123456
or
SHD2HH4
0
 

Author Comment

by:vzdog
ID: 22843429
Also I am getting an error:
Error Type:
Microsoft JET Database Engine (0x80040E14)
Syntax error in UPDATE statement.
/PMI/RecordUpdate.asp, line 44

it is:

conn.Execute sql
0
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 22844118
please response.write the value of sql variable before the execute, so you can inspect what goes wrong.
0
 

Author Comment

by:vzdog
ID: 22844169
I have no idea what you are telling me to do..
0
 
LVL 82

Accepted Solution

by:
hielo earned 500 total points
ID: 22844986
>>What about when it is a combination of both in the same field?
ie:
PD123456 or SHD2HH4

You need to look at the definition of your table and see if the field data type of your Table is numeric. You are focusing on the contents of your table. You need to focus on the definition of your table.

On another note, those are NOT numeric values. You can add numbers:
1+3=4

You cannot add: PD123456 + SHD2HH4

So that MUST be text field, in which case you need to enclose the values in apostrophes.
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Truncate is a DDL Command where as Delete is a DML Command. Both will delete data from table, but what is the difference between these below statements truncate table <table_name> ?? delete from <table_name> ?? The first command cannot be …
Configuring and using Oracle Database Gateway for ODBC Introduction First, a brief summary of what a Database Gateway is.  A Gateway is a set of driver agents and configurations that allow an Oracle database to communicate with other platforms…
This video explains at a high level about the four available data types in Oracle and how dates can be manipulated by the user to get data into and out of the database.
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
Suggested Courses

617 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question