Je crée un fichier .MDB qui inclut une base de données d'accès ms et un formulaire créé avec vb 6. J'utilise ms access 2000, et j'ai besoin de me connecter à ma base de données locale dans la MDB et une base de données MS SQL 2005 distante.Problème de connexion et d'interrogation dans ADO
Dans le code ci-dessous, je peux utiliser un msgbox pour afficher la valeur de retour du jeu de résultats, mais quand essayer de le sortir dans un textBox, par exemple: txtStatus.Value = txtStatus.Value & rstRecordSet.Fields(1) & vbCrLf
, il se bloque simplement. Et la méthode show dans l'exemple original du tutoriel a obtenu une méthode de Debug.Print quelque chose, mais il s'avère que je n'ai rien fait que je puisse voir. Je veux dire, VB n'a pas de panneau de console, où ira la déclaration d'impression?
Le code avec erreur obtenu:
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
Pouvez-vous énumérer l'erreur et quelle ligne il produit? – JeffO