【发布时间】:2011-03-16 09:06:09
【问题描述】:
我正在制作一个 .MDB 文件,其中包括一个 ms access 数据库和一个用 vb 6 制作的表单。我正在使用 ms access 2000,我需要连接到 MDB 中的本地数据库和远程 MS SQL 2005 年数据库。
在下面的代码中,我可以使用 msgbox 来显示从结果集中返回的值,但是当尝试在 textBox 中输出它时,例如:txtStatus.Value = txtStatus.Value & rstRecordSet.Fields(1) & vbCrLf,它只是挂起。并且教程中原始示例中显示的方法得到了一个 Debug.Print 方法,但事实证明没有做任何我能看到的事情。我的意思是,VB没有控制台面板,打印语句到哪里去?
出现错误的代码:
Function Testing()
On Error GoTo Error_Handling
Dim conConnection As New ADODB.Connection
Dim cmdCommand As New ADODB.Command
Dim rstRecordSet As New ADODB.Recordset
conConnection.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & _
App.Path & "\" & CurrentDb.Name & ";"
conConnection.CursorLocation = adUseClient
With cmdCommand
.ActiveConnection = conConnection
.CommandText = "SELECT * FROM Opt_In_Customer_Record;"
.CommandType = adCmdText
End With
With rstRecordSet
.CursorType = adOpenStatic
.CursorLocation = adUseClient
.LockType = adLockOptimistic
.Open cmdCommand
End With
If rstRecordSet.EOF = False Then
rstRecordSet.MoveFirst
Do
MsgBox "Record " & rstRecordSet.AbsolutePosition & " " & _
rstRecordSet.Fields(0).Name & "=" & rstRecordSet.Fields(0) & " " & _
rstRecordSet.Fields(1).Name & "=" & rstRecordSet.Fields(1)
rstRecordSet.MoveNext
Loop Until rstRecordSet.EOF = True
End If
conConnection.Close
Set conConnection = Nothing
Set cmdCommand = Nothing
Set rstRecordSet = Nothing
Exit Function
Error_Handling:
MsgBox "Error during function Testing!"
Exit Function
End Function
【问题讨论】:
-
你能列出错误以及它发生在哪一行吗?
标签: sql-server ms-access vb6 ado