视图字段范例

目录

如下代码演示如何使用 Command 属性和 ADO Recordset 对象,检索视图的字段信息。

Sub ViewFields()   Dim cnn As New ADODB.Connection
   Dim rst As New ADODB.Recordset
   Dim fld As ADODB.Field
   Dim cat As New ADOX.Catalog   ' 打开连接
   cnn.Open _
      "Provider=Microsoft.Jet.OLEDB.4.0;" & _
      "Data Source=c:\Program Files\Microsoft Office\" & _
      "Office\Samples\Northwind.mdb;"   ' 打开目录
   Set cat.ActiveConnection = cnn   ' 设置记录集的源
   Set rst.Source = cat.Views("AllCustomers").Command   ' 检索字段信息
   rst.Fields.Refresh
   For Each fld In rst.Fields
      Debug.Print fld.Name & ":" & fld.Type
   NextEnd Sub
www.2mysite.net