Views et Fields, exemples de collections (VB)
Le code suivant montre comment utiliser la propriété Command et l’objet Recordset pour récupérer des informations de champ pour l’affichage.
' BeginViewFieldsVB
Sub ViewFields()
On Error GoTo ViewFieldsError
Dim cnn As New ADODB.Connection
Dim rst As New ADODB.Recordset
Dim fld As ADODB.Field
Dim cat As New ADOX.Catalog
' Open the Connection
cnn.Open _
"Provider='Microsoft.Jet.OLEDB.4.0';" & _
"Data Source='Northwind.mdb';"
' Open the catalog
Set cat.ActiveConnection = cnn
' Set the Source for the Recordset
Set rst.Source = cat.Views("AllCustomers").Command
' Retrieve Field information
rst.Fields.Refresh
For Each fld In rst.Fields
Debug.Print fld.Name & ":" & fld.Type
Next
'Clean up
cnn.Close
Set cat = Nothing
Set rst = Nothing
Set cnn = Nothing
Exit Sub
ViewFieldsError:
If Not cnn Is Nothing Then
If cnn.State = adStateOpen Then cnn.Close
End If
Set cat = Nothing
Set rst = Nothing
Set cnn = Nothing
If Err <> 0 Then
MsgBox Err.Source & "-->" & Err.Description, , "Error"
End If
End Sub
' EndViewFieldsVB
Voir aussi
ActiveConnection, propriété (ADOX)
Catalog, objet (ADOX)
Command, propriété (ADOX)
View, objet (ADOX)
Views, collection (ADOX)
Commentaires
https://aka.ms/ContentUserFeedback.
Prochainement : Tout au long de l'année 2024, nous supprimerons progressivement les GitHub Issues en tant que mécanisme de retour d'information pour le contenu et nous les remplacerons par un nouveau système de retour d'information. Pour plus d’informations, voir:Soumettre et afficher des commentaires pour