我正在制作一个.MDB文件,其中包括一个ms访问数据库和一个使用vb 6创建的表单。我使用ms access 2000,并且需要连接到MDB中的本地数据库,和一个远程MS SQL 2005数据库。在ADO中连接和查询时遇到的问题
在下面的代码中,我可以使用msgbox来显示结果集中的返回值,但是当尝试在文本框中输出时,例如: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
你可以列出的错误,并线是发生哪些? – JeffO 2011-03-16 15:18:43