Link to home
Start Free TrialLog in
Avatar of vzdog
vzdog

asked on

Record Update ASP conn.Execute sql

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

Avatar of Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3]
Flag of Luxembourg image

you have no space between SET and Region:
  sql="UPDATE tblProactiveIssues SET "
  sql=sql & " Region='" & Request.Form("Region") & "',"

Open in new window

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") & "#,"
Avatar of vzdog
vzdog

ASKER

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?
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
Avatar of vzdog

ASKER

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

ASKER

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
please response.write the value of sql variable before the execute, so you can inspect what goes wrong.
Avatar of vzdog

ASKER

I have no idea what you are telling me to do..
ASKER CERTIFIED SOLUTION
Avatar of hielo
hielo
Flag of Wallis and Futuna image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial