ASP Database Fundamentals (Part 2) - Do I Have Data Now?
(Page 6 of 9 )
Well, now we have created a recordset object, and opened it. But how do we know if we actually found any data and if so, how much?
The recordset object has many properties. One of the most useful of these properties is the recordcount. By checking this property, you know if you actually found data with your search. For example:
<%
ConnectionString = "DSN=MyDB”
set conn = server.createobject("adodb.connection")
conn.open ConnectionString
set rs = Server.CreateObject("ADODB.recordset")
rs.open “Customers”, conn
if rs.recordcount >= 0 then
response.write “There are “ & rs.recordcount & “rows”
response.write “that match your search”
else
response.write “Error with recordset”
end if
rs.close
set rs = nothing
conn.close
set conn = nothing
%>
As you can see in the above example, a return of –1 constitutes some sort of error. This can be triggered if you try to check a recordcount without first opening the recordset, for example.
Next: How do I Get At The Data? >>
More ASP Articles
More By Rich Smith