ASP Database Fundamentals (Part 2) - Getting Data From Your Database
(Page 4 of 9 )
Now that we know how to create and destroy a recordset object, lets learn how to fetch some data.
Lets start simple. For our example, let’s assume that we have a database on the machine, with a DSN called “MyDB”. In this database, we have a table named “Customers”. This table contains 5 columns, named “CustomerID”, “FirstName”, “LastName”, “PhoneNumber”, and “Status”.
When creating a recordset, one of the parameters in the Open method determines the data that you wish to retrieve. If you want to return all of the records in a table, then you specify only the table name.
The following example will create a recordset containing all of the records in the Customers table:
<%
ConnectionString = "DSN=MyDB”
set conn = server.createobject("adodb.connection")
conn.open ConnectionString
set rs = Server.CreateObject("ADODB.recordset")
rs.open “Customers”, conn
‘ Logic to manipulate data here
rs.close
set rs = nothing
conn.close
set conn = nothing
%>
Next: How About SQL? >>
More ASP Articles
More By Rich Smith