Clone 메서드 예제(VBScript)
이 예제에서는 Clone 메서드를 사용하여 Recordset 복사본을 만든 다음, 사용자가 각 복사본의 레코드 포인터를 개별적으로 배치할 수 있도록 합니다.
ASP(활성 서버 페이지)에서 다음 예제를 사용합니다. 이 예제에서는 Microsoft Access와 함께 배포된 Northwind 데이터베이스를 사용합니다. 다음 코드를 잘라내어 메모장이나 다른 텍스트 편집기에 붙여넣고 CloneVBS.asp로 저장합니다. 모든 클라이언트 브라우저에서 결과를 볼 수 있습니다.
예제를 실행하려면 더 큰 테이블 수를 계산하도록 RsCustomerList.Source = "Customers"
줄을 RsCustomerList.Source = "Products"
로 변경합니다.
<!-- BeginCloneVBS -->
<% Language = VBScript %>
<%' use this meta tag instead of adovbs.inc%>
<!--METADATA TYPE="typelib" uuid="00000205-0000-0010-8000-00AA006D2EA4" -->
<HTML>
<HEAD>
<TITLE>ADO Clone Method</TITLE>
</HEAD>
<BODY>
<H1 align="center">ADO Clone Method</H1>
<HR>
<% ' to integrate/test this code replace the
' Data Source value in the Connection string%>
<%
' connection and recordset variables
Dim Cnxn, strCnxn
Dim rsCustomers, strSQLCustomers
Dim rsFirst, rsLast, rsCount
Dim rsClone
Dim CloneFirst, CloneLast, CloneCount
' open connection
Set Cnxn = Server.CreateObject("ADODB.Connection")
strCnxn = "Provider='sqloledb';Data Source=" & _
Request.ServerVariables("SERVER_NAME") & ";" & _
"Integrated Security='SSPI';Initial Catalog='Northwind';"
Cnxn.Open strCnxn
' create and open Recordset using object refs
Set rsCustomers = Server.CreateObject("ADODB.Recordset")
strSQLCustomers = "Customers"
rsCustomers.ActiveConnection = Cnxn
rsCustomers.CursorLocation = adUseClient
rsCustomers.CursorType = adOpenKeyset
rsCustomers.LockType = adLockOptimistic
rsCustomers.Source = strSQLCustomers
rsCustomers.Open
rsCustomers.MoveFirst
rsCount = rsCustomers.RecordCount
rsFirst = rsCustomers("CompanyName")
rsCustomers.MoveLast
rsLast = rsCustomers("CompanyName")
' create clone
Set rsClone = rsCustomers.Clone
rsClone.MoveFirst
CloneCount = rsClone.RecordCount
CloneFirst = rsClone("CompanyName")
rsClone.MoveLast
CloneLast = rsClone("CompanyName")
%>
<!-- Display Results -->
<H3>There Are <%=rsCount%> Records in the original recordset</H3>
<H3>The first record is <%=rsFirst%> and the last record is <%=rsLast%></H3>
<BR><HR>
<H3>There Are <%=CloneCount%> Records in the original recordset</H3>
<H3>The first record is <%=CloneFirst%> and the last record is <%=CloneLast%></H3>
<BR><HR>
<H4>Location of OLEDB Database</H4>
<%
' Show location of DSN data source
Response.Write(Cnxn)
' Clean up
If rsCustomers.State = adStateOpen then
rsCustomers.Close
End If
If rsClone.State = adStateOpen then
rsClone.Close
End If
If Cnxn.State = adStateOpen then
Cnxn.Close
End If
Set rsCustomers = Nothing
Set rsClone = Nothing
Set Cnxn = Nothing
%>
</BODY>
</HTML>
<!-- EndCloneVBS -->