明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 1678|回复: 3

[求助]关于ado调用数据库问题

[复制链接]
发表于 2005-7-7 17:24:00 | 显示全部楼层 |阅读模式
本帖最后由 作者 于 2005-7-7 20:34:59 编辑

在程序中我需要反复调用同一数据库中不同的表,代码如下,运行的时候提示需要运行对象。请大家帮我看看哪里错了,小女子万分感激!!!谢谢了!!! Private Sub UserForm_Initialize()

strPath = "D:\sheji\" & "\" '连接数据库
Set adoCon = New Connection
adoCon.CursorLocation = adUseClient
adoCon.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & _
strPath & "shujuku.mdb;"

'打开记录集
Set adoRs1 = New Recordset
adoRs1.Open "gxgtweijia", adoCon, adOpenDynamic, adLockOptimistic


RefreshList1 '将型号添加到列表框中

If adoRs1.RecordCount > 0 Then
adoRs1.MoveLast
adoRs1.MoveFirst

ExchangeData1 False
End If



Set adoRs2 = New Recordset
adoRs2.Open "zhitui", adoCon, adOpenDynamic, adLockOptimistic

RefreshList2 '将型号添加到列表框中

If adoRs2.RecordCount > 0 Then
adoRs2.MoveLast
adoRs2.MoveFirst

ExchangeData2 False
End If



End Sub Private Sub RefreshList1()
lstType1.Clear

Dim i As Integer
adoRs1.MoveFirst
For i = 0 To adoRs1.RecordCount - 1
lstType1.AddItem adoRs1.Fields("图号")
If Not adoRs1.EOF Then
adoRs1.MoveNext
End If

Next i

End Sub
Private Sub ExchangeData1(ByVal bSave As Boolean)
If bSave Then
adoRs1.Fields("H") = txt9.Text
adoRs1.Fields("H1") = txt8.Text
adoRs1.Fields("D") = txt7.Text


Else

txt9.Text = adoRs1.Fields("H")
txt8.Text = adoRs1.Fields("H1")
txt7.Text = adoRs1.Fields("D")

End If
End Sub Private Sub lstType1_click()
Dim i As Integer
i = lstType1.ListIndex

If i = -1 Then Exit Sub

If i <= adoRs1.RecordCount - 1 Then
adoRs1.MoveFirst
adoRs1.Move i
End If

ExchangeData1 False

End Sub Private Sub RefreshList2()
lstType2.Clear

Dim i As Integer
adoRs2.MoveFirst
For i = 0 To adoRs1.RecordCount - 1
lstType2.AddItem adoRs2.Fields("Ⅰ型图号")
If Not adoRs2.EOF Then
adoRs2.MoveNext
End If

Next i

End Sub
Private Sub ExchangeData2(ByVal bSave As Boolean)
If bSave Then
adoRs2.Fields("H1") = Text1.Text

Else

Text1.Text = adoRs2.Fields("H1")


End If
End Sub Private Sub lstType2_click()
Dim i As Integer
i = lstType2.ListIndex

If i = -1 Then Exit Sub

If i <= adoRs2.RecordCount - 1 Then
adoRs2.MoveFirst
adoRs2.Move i
End If

ExchangeData2 False

End Sub
发表于 2005-7-7 17:45:00 | 显示全部楼层
把程序完整贴上来方便别人调试.


        adoRs1.Open----adoRs1提示没有该属性
发表于 2005-7-7 21:27:00 | 显示全部楼层
  1.        '打开记录集
  2.        Set adoRs1 = New ADODB.Recordset
  3.        adoRs1.Open "gxgtweijia", adoCon, adOpenDynamic, adLockOptimistic
复制代码
 楼主| 发表于 2005-7-8 09:36:00 | 显示全部楼层
楼上的~~俺按照你说的改了~~可还是提示"要求对象"


您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|CAD论坛|CAD教程|CAD下载|联系我们|关于明经|明经通道 ( 粤ICP备05003914号 )  
©2000-2023 明经通道 版权所有 本站代码,在未取得本站及作者授权的情况下,不得用于商业用途

GMT+8, 2024-11-27 12:30 , Processed in 0.179722 second(s), 24 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表