Jump to content

ASP/ADO Demonstration Code As Seen on W3Schools


Eugene45

Recommended Posts

Hi Guys, I was using the code from the w3schools website for the ADO Demonstration. I was trying to do an UPDATE using the same code but changing the database path and other database names or fields to match my database field names. At the end it did not update my database. The Code I have is below( I have pasted 3 different coded forms because in the tutorial they are 3 forms and they link to each other the first of the 3 I have isForm7.asp........thendemo_db_edit.asp.........anddemo_db_submit.asp)Form7.asp

<%option explicit%><html><head><title>ADO - List Database Records</title></head><body><%dim conn,rs,xset conn=Server.CreateObject("ADODB.Connection")conn.provider="Microsoft.Jet.OLEDB.4.0"conn.Open "C:/Inetpub/wwwroot/MyWebProjects/Manual.mdb"set rs=Server.CreateObject("ADODB.Recordset")rs.open "SELECT * FROM Orders",conn%><h2>List Database Table</h2><p>Click on a button to modify a record.</p><table border="1" width="100%"><tr bgcolor="#b0c4de"><%for each x in rs.Fields      response.write("<th>" & (x.name) & "</th>")next%></tr><%do until rs.EOF%><tr bgcolor="#f0f0f0"><form method="post" action="demo_db_edit.asp" target="_blank"><%for each x in rs.Fields      if x.name="ID" then%>           <td><input type="submit" name="id" value="<%=x.value%>"></td>      <%else%>           <td><%Response.Write(x.value)%> </td>      <%end ifnext%></form><%rs.MoveNext%></tr><%looprs.closeset rs=nothingconn.closeset conn=nothing%></table></body></html>

demo_db_edit.asp

<%id=Request.Form("ID")if id="" then response.endset conn=Server.CreateObject("ADODB.Connection")conn.provider="Microsoft.Jet.OLEDB.4.0"conn.Open "C:/Inetpub/wwwroot/MyWebProjects/Manual.mdb"set rs = Server.CreateObject("ADODB.Recordset")rs.Open "Select * from Orders where Orders.[iD]=" & id , conn%><html><head><title>ADO - Edit DataBase Record</title></head><body><h2>Edit Database Table</h2><form method="post" action="demo_db_submit.asp" target="_blank"><input name="id" type="hidden" value=<%=id%>><table bgcolor="#b0c4de"><%for each x in rs.Fields      if x.name <> "ID" and x.name <> "Date Created" then%>           <tr>           <td><%=x.name%> </td>           <td><input name="<%=x.name%>" value="<%=x.value%>" size="20"></td>      <%end ifnextrs.closeconn.close%></tr></table><br /><input type="submit" name="action" value="Save"><input type="submit" name="action" value="Delete"></form></body></html>

demo_db_submit.asp

<html><head><title>ADO - Submit DataBase Record</title></head><body><h2>Submit to Database</h2><%on error resume nextset conn=Server.CreateObject("ADODB.Connection")conn.provider="Microsoft.Jet.OLEDB.4.0"conn.Open "C:/Inetpub/wwwroot/MyWebProjects/Manual.mdb"if Request.form("action")="Save" then      id=Request.Form("ID")      sql="UPDATE Orders SET Link='" & Request.Form("Link") & "',"      sql=sql & "Date Created='" & Request.Form("Date Created") & "',"      sql=sql & "Date_Visited='" & now() & "' WHERE Orders.[iD]=" & id conn.Execute sql, Recordsaffected if err <> 0 then Response.Write("You do not have permission to update this database!") else Response.Write("Record number " & id & " was updated.")end if      Response.Write("Submitting records has been disabled from this demo")end ifif Request.Form("action")="Delete" then      id=Request.Form("ID") 'conn.Execute "DELETE FROM Orders WHERE Orders.[iD]=" & id, Recordsaffected 'if err <> 0 then Response.Write("You do not have permission to delete a record from this database!")'else 'Response.Write("Record number " & id & " was deleted.")'end if      Response.Write("Deleting records has been disabled from this demo")end ifconn.close%></body></html>

I set the security on the access database to allow permission to everyone and the administrator ( so i am sure it is not the permissions that is the problem)My only guess for solving this problem was trying to differentiate between this two things "id" and "ID"........ One is a field name (or column name in the database) the other I think it should be the name attribute of the input tagI think i am using one of these wrongly. If this is not the problem why i cannot update the database then please show me what i can do to solve this problem.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...