Friday, December 14, 2007

How to get the total of records that have been deleted?

How to get the total of records that have been deleted?

If we need to find out How many records that have been deleted, we need to process 2 steps: one is to calculate the total, and another is to delete record.

For example:

<%

Set conn = Server.CreateObject("Adodb.Connection")

conn.Open "Driver={Microsoft Access Driver (*.mdb)};DBQ=" & Server.MapPath("db1.mdb")

Set rs = Server.CreateObject("Adodb.Recordset")

strSQL = "SELECT Count(*) FROM Member"

rs.Open strSQL ,conn,1,3

If rs.BOF OR rs.EOF Then

count=0

Else

count=rs.fields(0)

End If

rs.Close

Set rs = Nothing

conn.Execute "DELETE * FROM Member"

%>


Or, we can use the Connection to execute the delete function, and count How many records that have been affected:

<%

Set conn = Server.CreateObject("Adodb.Connection")

conn.Open "Driver={Microsoft Access Driver (*.mdb)};DBQ=" & Server.MapPath("db1.mdb")

conn.Excute "DELETE * FROM Member", count 'We will get How many records are being affected

%>

No comments: