Conn As New ADODB.Connection 与 Conn As String 两种执行有什么区别?
================ 第一种 ====================================
Public Conn As New ADODB.Connection
Public Rs As New ADODB.Recordset
Conn.CursorLocation = adUseClient
Conn.ConnectionString = "Provider=SQLOLEDB.1;Password=sa;Persist Security Info=True;User ID=sa;Initial Catalog=db_swcl;Data Source=192.168.5.25"
Conn.Open
Rs.Open "select * from user", Conn, adOpenDynamic, adLockOptimistic
Do While Not Rs.EOF
Rs.MoveNext
Loop
Rs.Close
Set Rs = Nothing
Conn.Close
Set Conn = Nothing
================== 第二种 ======================================
Public Conn As String
Public Rs As New ADODB.Recordset
Conn = "Provider=SQLOLEDB.1;Password=sa;Persist Security Info=True;User ID=sa;Initial Catalog=db_swcl;Data Source=192.168.5.25"
Rs.CursorLocation = adUseClient
Rs.Open "select * from user", Conn, adOpenDynamic, adLockOptimistic
Do While Not Rs.EOF
Rs.MoveNext
Loop
Rs.Close
Set Rs = Nothing
*****************************************************************
请问以上两种定义 Conn 不同,但实际使用有什么不同?
还有在查询时加上 CursorLocation = adUseClient
与没加上 CursorLocation = adUseClient
又有什么实质不同呢?
[最优解释]
一: Recordset.Open 使用现有的 Connection 实例,如果同时开多个 RecordSet,始终只有一个连接。
二: Recordset.Open 自动创建新的 Connection 实例,如果同时开多个 RecordSet,就会有多个连接。
CursorLocation = adUseClient 使用客户端游标,Recordset.Open 会马上把所有数据取到本地。
CursorLocation = adUseServer 使用服务端游标,数据是逐步地随着 MoveNext 一批批取到本地的。
[其他解释]
何不转到VB板块去问一下?