Code for using disconnected data record set in ASP program

Source: Internet
Author: User

Therefore, to save server resources, you should close the connection whenever possible to release the resources occupied by the connection. This technology that closes the connection of the record set without closing the record set is called the disconnection record set, this record set is called a disconnected record set.

Next we will use an example to describe how to use this technology (NorthWind. mdb is a database that comes with Microsoft Access97, and the file adovbs. inc can be found under C: \ Program Files \ Common Files \ System \ ADO ):Copy codeThe Code is as follows: <% @ LANGUAGE = VBScript %>
<! -- # Include file = "adovbs. inc" -->
<%
Response. Expires = 0
Dim Cnn, objRS, strOut, strQ, strC
StrC = "Driver = {Microsoft Access Driver (*. mdb)}; DBQ =" & Server. MapPath ("\ asp24") & "\ NorthWind. mdb ;"
'Establish a connection
Set Cnn = Server. CreateObject ("ADODB. Connection ")
Cnn. Open StrC

'Create A Recordset object

Set objRS = Server. CreateObject ("ADODB. Recordset ")
ObjRS. CursorLocation = adUseClient
ObjRS. CursorType = adOpenStatic
ObjRS. LockType = adLockOptimistic

StrQ = "SELECT forwarder ID, company name, phone number FROM forwarder"
ObjRS. Open strQ, Cnn, ad1_text
Set objRS. ActiveConnection = Nothing 'disconnects the record Set.
Cnn. Close 'Close the connection
Set Cnn = Nothing

Response. Write "<HTML> <BODY>"
'Use the disconnected record set below
Do While (Not objRS. EOF)
StrOut = objRS ("Freight dealer ID") & "," & objRS ("company name") & "," & objRS ("phone ")
Response. Write Server. HTMLEncode (strOut) & "<BR>"
ObjRS. MoveNext
Loop
Response. Write "<BR> prepare to add or insert a record :"

'If you want to update the database, you need to reestablish the connection.
Set Cnn = Server. CreateObject ("ADODB. Connection ")
Cnn. Open strC
Set objRS. ActiveConnection = Cnn
ObjRS. Filter = "company name = 'wu feng '"
If objRS. EOF Then
ObjRS. AddNew
ObjRS ("company name") = "Wu Feng"
ObjRS ("phone") = "571-7227298"
ObjRS. Update
Response. Write "if the record that meets this condition does not exist, Add. <BR>"
Else
ObjRS ("phone") = "571-7227071"
Response. Write "if the record meets this condition exists, Update. <BR>"
ObjRS. Update
End If
Set objRS. ActiveConnection = Nothing
Cnn. close
Set Cnn = Nothing
ObjRS. Close
Set objRS = Nothing
Response. Write "</BODY> </HTML>"
%>

Related Article

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.