Monday, December 17, 2007

How to detect the RecordSet if it is empty

How to detect the RecordSet if it is empty

S T E P - 1

- We can use 2 methods to detect the RecordSet is empty.

- First method is using BOF(Beginning Of File) and EOF(End Of File).

Dim oConn

Dim oRs

Set oConn = Server.CreateObject("ADODB.Connection")

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

Set oRs = oConn.Execute("SELECT * FROM Member")

If oRs.BOF and oRs.EOF Then

Response.Write("The table is empty")

End If

S T E P - 2

- Second method is to use the RecordCount properties:

- If the RecordCount = 0 , that means no record in the table:

Dim oConn

Dim oRs

Set oConn = Server.CreateObject("ADODB.Connection")

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

Set oRs = oConn.Execute("SELECT * FROM Member")

If oRs.RecordCount = 0 Then

Response.Write("The table is empty")

End If

No comments: