Codefixer - ASP tutorials, resources and software
asp.netPRO “Best ASP.NET Host” – DiscountASP.NET
Home   Articles   Resources   ASP directory   ASP Tutorials   Code Snippets   ASP Applications   Forum
Wednesday 14 May
MembersPro PayPal - ASP Membership software

ASP.NET 3.5 Hosting – DiscountASP.NET


ASP Partner ASP Partner ASP Partner more partners...

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>
<%
'declare your variables
Dim connection, recordset
Dim SQL, sConnString

'declare SQL statement that will query the database
SQL="SELECT * FROM tblFriends"

'define the connection string, specify database
'driver and the location of database
sConnString="PROVIDER=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & Server.MapPath("Friends.mdb")
'create an ADO connection and recordset
Set connection = Server.CreateObject("ADODB.Connection")
Set recordset = Server.CreateObject("ADODB.Recordset")
'Open the connection to the database
connection.Open sConnString

'Open the recordset object, execute the SQL statement
recordset.Open SQL,connection
If recordset.eof then
 response.write "There were no records returned."
Else
 response.write "There are records returned."
End if

'close the connection and recordset objects freeing up resources
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.

Previous: UPDATING Records
LinksPro - Directory  and Link  Management Software




ASP.NET 3.5/2.0 Web Hosting: 3 Months FREE – Click Here!




About | Contact | Advertise | Feedback | Hire Us | Link

Site developed by Michael Wall - Web Design Belfast N.Ireland.
Copyright © 2000-2008. All rights reserved.

Do you intend to move to ASP.NET or have you already?
Yes will do
Have done
ASP does fine
Not a priority


Directory Software