With adoconnection
If .State = adStateOpen Then '不判断则出现3705号错误
.Close
End If .ConnectionTimeout = 2
.ConnectionString = cnnstr 'connectstring
.open
If .State = adStateOpen Then
MsgBox "成功连接数据库。"
Else
MsgBox "连接数据库失败!"
End If
End With
With adorecordset '记录集的通用设置值
If .State = adStateOpen Then '不判断则出现3705号错误
.Close
End If .ActiveConnection = adoconnection
.CursorLocation = adUseClient
.CursorType = adOpenStatic
.LockType = adLockBatchOptimistic
.source = Adodc1.RecordSource '"SELECT * FROM 供应商"
.open
End With
Set DataGrid1.DataSource = adorecordset '显示SQL命令结果
If .State = adStateOpen Then '不判断则出现3705号错误
.Close
End If .ConnectionTimeout = 2
.ConnectionString = cnnstr 'connectstring
.open
If .State = adStateOpen Then
MsgBox "成功连接数据库。"
Else
MsgBox "连接数据库失败!"
End If
End With
With adorecordset '记录集的通用设置值
If .State = adStateOpen Then '不判断则出现3705号错误
.Close
End If .ActiveConnection = adoconnection
.CursorLocation = adUseClient
.CursorType = adOpenStatic
.LockType = adLockBatchOptimistic
.source = Adodc1.RecordSource '"SELECT * FROM 供应商"
.open
End With
Set DataGrid1.DataSource = adorecordset '显示SQL命令结果
rs.Open query, conn, adOpenDynamic, adLockOptimistic
adOpenDynamic:动态游标(还有三种,只读,关键字,静态)
adLockOptimistic:批处理锁(还有三种,只读,乐观,悲观)
用上面说的那个就应该可以了。
将Connection.CursorLocation = adUseClient
RecordSet.Open SQL语句, adOpenStatic, adLockBatchOptimistic