Article ID: 188857
Article Last Modified on 3/2/2005
Option Explicit
Dim cn As New ADODB.Connection
Dim cmd As New ADODB.Command
Dim rs As New ADODB.Recordset
Private Sub Command1_Click()
With cn
.CursorLocation = adUseServer
.ConnectionString = "dsn=yourdatasourcename"uid=yourUserId;pwd=yourPassword
.Open
End With
rs.CursorType = adOpenKeyset
rs.LockType = adLockOptimistic
End Sub
Private Sub Command2_Click()
Set rs = cn.Execute("select * from authors")
End Sub
Private Sub Command3_Click()
With cmd
.ActiveConnection = cn
.CommandType = adCmdText
.CommandText = "select * from authors"
End With
Set rs = cmd.Execute
End Sub
Private Sub Command4_Click()
rs.Open "select * from authors", cn
End Sub
Private Sub Command5_Click()
Debug.Print "CursorLocation " & rs.CursorLocation; ""
Debug.Print "cursortype " & rs.CursorType
Debug.Print "locktype " & rs.LockType
End Sub
Private Sub Command6_Click()
If rs.State = 1 Then
rs.Close
End If
If Not rs Is Nothing Then
Set rs = Nothing
End If
rs.CursorLocation = adUseServer
rs.CursorType = adOpenKeyset
rs.LockType = adLockOptimistic
End Sub
Private Sub Command7_Click()
If Not rs Is Nothing Then
Set rs = Nothing
End If
If cn.State = 1 Then
cn.Close
End If
If Not cmd Is Nothing Then
Set cmd = Nothing
End If
If Not cn Is Nothing Then
Set cn = Nothing
End If
Unload Me
End Sub
Private Sub Form_Load()
Command1.Caption = "connect"
Command2.Caption = "connection.execute"
Command3.Caption = "command.execute"
Command4.Caption = "open recordset"
Command5.Caption = "print recordset attributes"
Command6.Caption = "close recordset"
Command7.Caption = "quit"
End Sub
Cursorlocation Cursortype Locktype
----------------------------------------------
0 N/A adforwardonly N/A
1 N/A adopenkeyset readonly
2 aduseserver adopendynamic pessimistic
3 aduseclient adopenstatic optimistic
Additional query words: kbado forward-only server-side read-only
Keywords: kbprb KB188857