Sun Chili!Soft ASP Sun Chili!Soft
ASP Sun Microsystems

 

ADO Recordset Object Close Method

Closes an open object and any dependent objects.

Close Method Syntax

object.Close

Close Method Remarks

Use the Close method to close a Recordset object to free any associated system resources. Closing an object does not remove it from memory; you may change its property settings and open it again later. To completely eliminate an object from memory, set the object variable to Nothing.

Using the Close method to close a Recordset object releases the associated data and any exclusive access you may have had to the data through this particular Recordset object. You can later call the ADO Recordset Object Open Method to reopen the Recordset with the same or modified attributes. While the Recordset object is closed, calling any methods that require a live cursor generates an error.

If an edit is in progress while in immediate update mode, calling the Close method generates an error; call the ADO Recordset Object Update Method or ADO Recordset Object CancelUpdate Method first. If you close the Recordset object during batch updating, all changes since the last ADO Recordset Object UpdateBatch Method call are lost.

If you use the Clone method to create copies of an open Recordset object, closing the original or a clone does not affect any of the other copies.

Close Method Examples

This VBScript example uses the Open and Close methods on both Recordset and Connection objects that have been opened.

<!-- #Include file="ADOVBS.INC" -->

<HTML><HEAD>

<TITLE>ADO 1.5 Open Method</TITLE>

</HEAD><BODY>

<FONT FACE="MS SANS SERIF" SIZE=2>

<Center><H3>ADO Open Method</H3>

<TABLE WIDTH=600 BORDER=0>

<TD VALIGN=TOP ALIGN=LEFT COLSPAN=3><FONT SIZE=2>

<!--- ADO Connection used to create 2 recordsets-->

<%

Set OBJdbConnection = Server.CreateObject("ADODB.Connection")

OBJdbConnection.Open "AdvWorks"

SQLQuery = "SELECT * FROM Customers"

'First Recordset RSCustomerList

Set RSCustomerList = OBJdbConnection.Execute(SQLQuery)

'Second Recordset RsProductist

Set RsProductList = Server.CreateObject("ADODB.Recordset")

RsProductList.CursorType = adOpenDynamic

RsProductList.LockType = adLockOptimistic

RsProductList.Open "Products", OBJdbConnection

%>

<TABLE COLSPAN=8 CELLPADDING=5 BORDER=0>

<!-- BEGIN column header row for Customer Table-->

<TR><TD ALIGN=CENTER BGCOLOR="#008080">

<FONT STYLE="ARIAL NARROW" COLOR="#ffffff" SIZE=1>Company Name</FONT></TD>

<TD ALIGN=CENTER BGCOLOR="#008080">

<FONT STYLE="ARIAL NARROW" COLOR="#ffffff" SIZE=1>Contact Name</FONT></TD>

<TD ALIGN=CENTER WIDTH=150 BGCOLOR="#008080">

<FONT STYLE="ARIAL NARROW" COLOR="#ffffff" SIZE=1>E-mail address</FONT></TD>

<TD ALIGN=CENTER BGCOLOR="#008080">

<FONT STYLE="ARIAL NARROW" COLOR="#ffffff" SIZE=1>City</FONT></TD>

<TD ALIGN=CENTER BGCOLOR="#008080">

<FONT STYLE="ARIAL NARROW" COLOR="#ffffff" SIZE=1>State/Province</FONT></TD></TR>

<!--Display ADO Data from Customer Table-->

<% Do While Not RScustomerList.EOF %>

<TR><TD BGCOLOR="f7efde" ALIGN=CENTER>

<FONT STYLE="ARIAL NARROW" SIZE=1>

<%= RSCustomerList("CompanyName")%>

</FONT></TD>

<TD BGCOLOR="f7efde" ALIGN=CENTER>

<FONT STYLE="ARIAL NARROW" SIZE=1>

<%= RScustomerList("ContactLastName") & ", " %>

<%= RScustomerList("ContactFirstName") %>

</FONT></TD>

<TD BGCOLOR="f7efde" ALIGN=CENTER>

<FONT STYLE="ARIAL NARROW" SIZE=1>

<%= RScustomerList("ContactLastName")%>

</FONT></TD>

<TD BGCOLOR="f7efde" ALIGN=CENTER>

<FONT STYLE="ARIAL NARROW" SIZE=1>

<%= RScustomerList("City")%>

</FONT></TD>

<TD BGCOLOR="f7efde" ALIGN=CENTER>

<FONT STYLE="ARIAL NARROW" SIZE=1>

<%= RScustomerList("StateOrProvince")%>

</FONT></TD></TR>

<!-Next Row = Record Loop and add to html table-->

<%

RScustomerList.MoveNext

Loop

RScustomerList.Close

OBJdbConnection.Close

%>

</TABLE>

<HR>

<TABLE COLSPAN=8 CELLPADDING=5 BORDER=0>

<!-- BEGIN column header row for Product List Table-->

<TR><TD ALIGN=CENTER BGCOLOR="#800000">

<FONT STYLE="ARIAL NARROW" COLOR="#ffffff" SIZE=1>Product Type</FONT></TD>

<TD ALIGN=CENTER BGCOLOR="#800000">

<FONT STYLE="ARIAL NARROW" COLOR="#ffffff" SIZE=1>Product Name</FONT></TD>

<TD ALIGN=CENTER WIDTH=350 BGCOLOR="#800000">

<FONT STYLE="ARIAL NARROW" COLOR="#ffffff" SIZE=1>Product Description</FONT></TD>

<TD ALIGN=CENTER BGCOLOR="#800000">

<FONT STYLE="ARIAL NARROW" COLOR="#ffffff" SIZE=1>Unit Price</FONT></TD></TR>

<!-- Display ADO Data Product List-->

<% Do While Not RsProductList.EOF %>

<TR> <TD BGCOLOR="f7efde" ALIGN=CENTER>

<FONT STYLE="ARIAL NARROW" SIZE=1>

<%= RsProductList("ProductType")%>

</FONT></TD>

<TD BGCOLOR="f7efde" ALIGN=CENTER>

<FONT STYLE="ARIAL NARROW" SIZE=1>

<%= RsProductList("ProductName")%>

</FONT></TD>

<TD BGCOLOR="f7efde" ALIGN=CENTER>

<FONT STYLE="ARIAL NARROW" SIZE=1>

<%= RsProductList("ProductDescription")%>

</FONT></TD>

<TD BGCOLOR="f7efde" ALIGN=CENTER>

<FONT STYLE="ARIAL NARROW" SIZE=1>

<%= RsProductList("UnitPrice")%>

</FONT></TD>

<!-- Next Row = Record -->

<%

RsProductList.MoveNext

Loop

'Remove Objects from Memory Freeing

Set RsProductList = Nothing

Set OBJdbConnection = Nothing

%>

</TABLE></FONT></Center></BODY></HTML>

Copyright 2002 Sun Microsystems, Inc. All rights reserved. Legal Notice.