|
Adodc1.Recordset.MoveNext If Adodc1.Recordset.EOF Then Adodc1.Recordset.MoveLast Command1.Enabled = True Command2.Enabled = True Command3.Enabled = False Command4.Enabled = False Else Command1.Enabled = True Command2.Enabled = True Command3.Enabled = True Command4.Enabled = True End If Dim cnstring As String '用于存放连接字符串的 cnstring = "Provider=OraOLEDB.Oracle.1;Persist Security Info=False;User ID=dytd;PassWord=dytd;Data Source=dytd_maipu" Mycn.Open cnstring Mycn.CursorLocation = adUseClient Adodc2.Recordset.Open "select * from DJ_CSDJ_DJDCB_ZJBS where dcdz_bh='" & Trim(txt1.Text) & "'" Mycn.Close End Sub 问题是这样的,在一个窗体里有adodc1和adodc2两个控件,我要实现的功能是,点激下移的时候,adodc1的记录移动到下一条,而adodc2根据1所移的记录中的一条数据进行查询 现在错误是“3705 对象打开时,操作不被允许”!大家看看我的下移,和窗体的代码怎么修改一下,就能实现我 要的功能呢?!谢谢 Private Sub Form_Load() If Adodc1.Recordset.BOF And Adodc1.Recordset.EOF Then MsgBox "库里还没有记录请先填加再查询!!!", vbOKOnly + vbExclamation, "信息提示" Command1.Enabled = False Command2.Enabled = False Command3.Enabled = False Command4.Enabled = False Else Command1.Enabled = False Command2.Enabled = False Command3.Enabled = True Command4.Enabled = True End If End Sub |
|
|
|
Adodc2.Recordset.Open之前要先关闭!!
|
|
|
问题就是在什么地方关闭了,在loadform的时候,那不行,因为我还要让它显示数据呢
|
|
|
在Adodc2.Recordset.Open 之前就行了!
|
|
|
那你就先关闭再打开
on error goto errorhandle: Adodc1.Recordset.MoveNext If Adodc1.Recordset.EOF Then Adodc1.Recordset.MoveLast Command1.Enabled = True Command2.Enabled = True Command3.Enabled = False Command4.Enabled = False Else Command1.Enabled = True Command2.Enabled = True Command3.Enabled = True Command4.Enabled = True End If Dim cnstring As String '用于存放连接字符串的 cnstring = "Provider=OraOLEDB.Oracle.1;Persist Security Info=False;User ID=dytd;PassWord=dytd;Data Source=dytd_maipu" Mycn.Open cnstring Mycn.CursorLocation = adUseClient Adodc2.Recordset.Open "select * from DJ_CSDJ_DJDCB_ZJBS where dcdz_bh='" & Trim(txt1.Text) & "'" Mycn.Close errorhandle: if err.number=3705 then Mycn.close resume endif |
|
|
你何必这样用两个ADODB呢,你再打开数据库的时候把要关联的数据或数据库一起打开做为一个查询就可以了,你点下移的时候就相当于再同一个数据库中操作了!这样的速度还要快的多啊!
|
|
|
访问同一个表,记录集打开后要注意关闭
|
|