RecordSet.Open

recordset.Open[ Source,ActiveConnection,CursorType,LockType,Options]

Source:设置一个数据源(Command对象、SQL命令、表名称、存储过程等等);

ActiveConnection:一个Connection对象变量,或者是包含ConnectionString信息的字符串;

CursorType:打开Recordset时的指针类型
adOpenForwardOnly(0):Forward-Only指针;
adOpenKeyset(1):Keyset指针;
adOpenDynamic(2):Dynamic指针;
adOpenStatic(3):Static指针

LockType:打开Recordset时的锁定类型
adLockReadOnly(1):只读,无法改变数据----默认值;
adLockPessimistic(2):排他性锁定---编辑时立即锁定数据来源的该条记录;
adLockOptimistic(3):非排他性锁定----直到调用Update方法时,才锁定该条记录;
adLockBatchOptimistic(4):非排他性批量更新---需先设置为批量更新方式

Option:指定Source参数为哪种内容类型
adCmdtext(1)
adCmdTable(2)
adCmdtableDirect(3)
adCmdStoredProc(4)
adCmdFile(256)等等

舉例:

public function getrs(sql as string,optional tdb as trueoledbgrid70.dbgrid) as adodb.recordset

on error goto rserror

set getrs =new adodb.recordset

getrs.cursorlocation=aduseclient

getrs.open sql ,cnn,adopendynamic,adlockbatchoptimistic

if not tdb is nothing then set tdb.datasource=getrs

exit function

rserror:

msgbox error.description

end function


adLockReadOnly 常数值为1 vb缺省值:Recordset对象以只读方式启动,无法运行AddNew、Update及Delete等方法

adLockPrssimistic 常数值为2 :当数据源正在更新时,系统会暂时锁住其他用户的动作,以保持数据一致性。

adLockOptimistic 常数值为3 :当数据源正在更新时,系统并不会锁住其他用户的动作,其他用户可以对数据进行增、删、改的操作。

adLockBatchOptimistic 常数值为4 :当数据源正在更新时,其他用户必须将CursorLocation属性改为adUdeClientBatch才能对数据进行增、 删、改的操作。


Sqlstr(查询字符串,可以是SQL语句\表名\视图名\存储过程等),
adcmdtext就是指上面的这个字符串是什么类型,adcmdtext是SQL语句,AdCmdTable是指表...等等了

原文地址:https://www.cnblogs.com/streetpasser/p/2825282.html