ASP Database Fundamentals (Part 4) - Deleting Information
(Page 7 of 9 )
Finally, we are down to the last topic. Deleting or removing data from your database is the last fundamental function we are missing. There are two basic ways to accomplish this using ADO (sound like a pattern is forming here?), just like adding and modifying records.
Using the recordset object, there is a “delete” method to delete the current record. The delete method has an optional parameter, but for the sake of simplicity we are not going to explore it here. When using the delete method keep in mind that the current record is deleted and is still the current record in the recordset. If you attempt to retrieve values from the record, an error will occur. This deleted record will hold its place in the recordset until you move to another record.
An example:
<%
ConnectionString = "DSN=MyDB”
set conn = server.createobject("adodb.connection")
conn.open ConnectionString
set rs = Server.CreateObject("ADODB.recordset")
rs.open “Customers”, conn
‘ Go through all records deleting “unused” customers
do until rs.EOF
if rs(“Status”) = “InActive” then
rs.delete
end if
rs.MoveNext
loop
rs.close
set rs = nothing
conn.close
set conn = nothing
%>
Next: Deleting Using the Connection Object >>
More ASP Articles
More By Rich Smith