1

使用VB6 & ADODB 开放存取2000 DB。连接字符串打开。我通过在打开记录集之前获取连接的 .STATE 来验证这一点。

Private Sub Form_Load()
  With conn
    .ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" _
         & "Data Source=C:\Path to database\MyDb.mdb;"
  End With
  conn.Open

  Debug.Print conn.ConnectionString
End Sub

下面的代码片段显示了发生错误的行

Private Sub btnGO_Click()
Dim strDbName As String
Dim strg As String
Dim chkr As Variant
Dim MyCnt As Integer

chkr = False

Dim strsql As String
strsql = "Select * from [dbo].[BidItem]"

With rst
    .ActiveConnection = conn
    .Source = "Select * from [dbo].[BidItem]"
    .Open   -------------------------------------> Errors at this point
End With


With rst
    If Not .EOF And Not .BOF Then
        .MoveFirst
        MyCnt = .RecordCount
    End If
End With

MsgBox ("open")
MsgBox ("Count of TableRows: " & MyCnt)
Set rst = Nothing

End Sub

编辑:确切的错误信息是Run-Time Error '-2147467259 (80004005)': Could not find file 'C:\Program Files (x86)\Microsoft Visual\VB98\dbo.mdb'

4

1 回答 1

0

您的两个片段都被编码为“私人”,这意味着它们不能很好地共享。您的“开始”按钮不清楚在表单加载之前实际的“ActiveConnection”设置是什么。

于 2013-11-11T14:39:32.047 回答