Are there any records?
Download
the code
In this following example our Access database is called 'Friends.mdb'
and the table 'tblFriends'. The table has 3 fields firstly an
'ID' field that is an autonumber, secondly a field called 'FirstName'
which is a textfield and lastly another textfield called 'SurName'.
You can add some records into your table and also try the code
without any records.
Our file is called 'records.asp'.
<%@ Language="VBScript" %>
<% Option Explicit %>
<html>
<head>
<title>Are there any records returned</title>
</head>
<body>
<%
Dim connection, recordset
Dim SQL, sConnString
SQL="SELECT * FROM tblFriends"
sConnString="PROVIDER=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & Server.MapPath("Friends.mdb")
Set connection = Server.CreateObject("ADODB.Connection")
Set recordset = Server.CreateObject("ADODB.Recordset")
connection.Open sConnString
recordset.Open SQL,connection
If recordset.eof then
response.write "There were no records returned."
Else
response.write "There are records returned."
End if
Recordset.Close
Set Recordset=nothing
Connection.Close
Set Connection=nothing
%>
</body>
</html>
Depending on whether you had records in the table you will either
get the message 'There were no records returned.' or 'There are
records returned'. It's all fairly straightforward.
Site developed by Michael Wall - Web Design Belfast N.Ireland.
Copyright © 2000-2008. All rights reserved.
|