Aggiornare Record ADO
- Pagina Precedente Aggiungere ADO
- Pagina Successiva Eliminare ADO
Possiamo utilizzare SQL UPDATE per aggiornare una registrazione della tabella del database.
Aggiornamento dei record della tabella del database
Speriamo di aggiornare una registrazione della tabella Customers del database Northwind. Prima di tutto, dobbiamo creare una tabella per elencare tutte le registrazioni nella Customers.
<html> <body> <% set conn = Server.CreateObject(\ conn.Provider = \ conn.Open \ rs.open "SELECT * FROM customers",conn %> <h2>Elenco Database</h2> <table border="1" width="100%"> <tr> <% for each x in rs.Fields response.write("<th>" & ucase(x.name) & "</th>") next %> </tr> <% do until rs.EOF %> <tr> <form method=\ <% for each x in rs.Fields if lcase(x.name)="customerid" then> <td> <input type="submit" name="customerID" value="<%=x.value%>"> </td> <%else%> <td><%Response.Write(x.value)%></td> <%end if> next %> </form> <%rs.MoveNext%> </tr> <% loop conn.close %> </table> </body> </html>
Se l'utente clicca sul pulsante nella colonna \
<html> <body> <h2>Update Record</h2> <% set conn = Server.CreateObject(\ conn.Provider = \ conn.Open \ cid = Request.Form(\ if Request.form(\ rs.open \ %> <form method=\ <table> <%for each x in rs.Fields%> <tr> <td><%=x.name%></td> <td><input name=\ <%next%> </tr> </table> <br /><br /> <input type=\ </form> <% else sql = sql & \ sql=sql & "city='" & Request.Form("city") & "'," sql=sql & "postalcode='" & Request.Form("postalcode") & "'," sql=sql & "country='" & Request.Form("country") & "'" sql=sql & " WHERE customerID='" & cid & "'" on error resume next conn.Execute sql se err<>0 allora response.write("Nessuna autorizzazione di aggiornamento!") else response.write("Record " & cid & " fu aggiornato!") fine if fine if conn.close %> </body> </html>
- Pagina Precedente Aggiungere ADO
- Pagina Successiva Eliminare ADO