|
Once again, we’ll need to do some changes in listing.asp. We’ll also create delete.asp
We’ll start by adding one more column to our table in listing.asp
Here’s just the new code for that table, replace this in listing.asp:
<%
Dim objRS
Set objRS = Server.CreateObject ("ADODB.Recordset")
objRS.Open "Users", strConnect, adOpenForwardOnly, adLockReadOnly, adCmdTable
response.write "<table width='500' border='0' cellpadding='2'><tr bgcolor='#CCD6E0'>" & _
"<td><b>User ID</b></td><td><b>Full Name</b></td><td><b>Email</b></td><td><b>Edit</b>”
“</td><td><b>Delete</b></td></tr>"
While Not objRS.EOF
Response.Write "<tr><td>"
Response.Write objRS("ID") & "</td><td>" &objRS("Name") & " "&objRS("Lastname")& _
"</td><td>"&objRS("Email")&"</td><td><a href='edit.asp?id="&objRS("id")&"'>Edit</a></td>"& _
"<td><a href='delete.asp?id="&objRS("id")&"'>Delete</a></td></tr>"
objRS.MoveNext
Wend
response.write "</table>"
objRS.Close
Set objRS = Nothing
%>
Once again, we send the id through the link as a way to tell delete.asp which record to delete.
Here’s the code for delete.asp:
<% Option Explicit %>
<!-- #INCLUDE FILE="DBInfo.asp" -->
<%
Dim objRS, id,strQuery
Set objRS = Server.CreateObject ("ADODB.Recordset")
strQuery= "select * from USERS where id="&request.QueryString("id")
objRS.Open strQuery, strConnect, adOpenStatic, adLockOptimistic, adCmdText
objRS.Delete
objRS.Update
objRS.Close
Set objRS = Nothing
response.redirect "listing.asp"
%>
So far, you’ll have the following files in your project:
1. example.mdb
2. DBInfo.asp
3. listing.asp
4. addnew.asp
5. edit.asp
6. saveedit.asp
7. delete.asp
With all these files, we have a pretty good draft of a web application.
Hopefully, you did learn from this example and if you have any questions or
need some help, please let me know!
On later tutorials, I’ll refer to this same application to add some more cool stuff
(field validation, delete multiple records, add new tables, etc) and build a better application.
Do you have any questions?
Write me, Romeo Marquez Guzman romeo@gelattina.com
www.gelattina.com |