Asp data source access overview 2 (from IIS5.0 document)

Source: Internet
Author: User
Use Recordset object to process results
To retrieve data, check results, and change the database, ADO provides a Recordset object. As shown in the name, the "Recordset" object has the function to retrieve and display database rows (or "records"), depending on your query constraints. The "Recordset" object retains the position of each record returned by the query, so that you can view all the results, one at a time.
Retrieve record set
A successful Web data application uses both the "Connection" object to establish a link and the "Recordset" object to process the returned data. By combining some of the special features of these two objects, the developed database application can execute almost all data processing tasks. For example, the following server-side script uses the "Recordset" object to execute the SELECT command of SQL. This SELECT command is used to retrieve information sets based on query constraints. This query also contains the SQL WHERE clause, which limits the query to a specified standard. In this example, the WHERE clause limits the query to all records WHERE the last name field in the MERS database table contains Smith.
<%
'Establish a data source connection
StrConnectionString = "Provider = Microsoft. Jet. OLEDB.4.0; Data Source = C: DataEmployees. mdb"
Set cnn = Server. CreateObject ("ADODB. Connection ")
Cnn. Open strConnectionString
'Example Recordset object
Set rstCustomers = Server. CreateObject ("ADODB. Recordset ")
'Use the Open method to Open a record set
And use the Connection established through the Connection object.
StrSQL = "SELECT FirstName, LastName from mers where LastName = 'Smith '"
RstCustomers. Open strSQL, cnn
'Traverse record set and display result
'And use the MoveNext method to increment the record position.
Set objFirstName = rstCustomers ("FirstName ")
Set objLastName = rstCustomers ("LastName ")
Do Until rstCustomers. EOF
Response. Write objFirstName & "& objLastName &" <BR>"
RstCustomers. MoveNext
Loop
%>
Note: In the preceding example, the "Connection" object establishes a database Connection, while the "Recordset" object uses the same Connection to retrieve results from the database. This method is useful when you need to precisely configure the method for establishing database links. For example, if you want to specify the time delay before the Connection is terminated, you may need to use the "Connection" object to set this attribute. However, if you only want to use the default connection property of ADO to establish a connection, you can use the "Open" method of the "Recordset" object to create a connection:

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.