Link 所有带前缀的视图

Link All Views With Prefix

我已将此代码用于表格中的 link,但我试图将其更改为 View 但没有任何内容被 link 编辑,即使符合条件。我应该在视图中将什么更改为 link?

Dim c As ADODB.Connection
Dim r As ADODB.Recordset
Dim f As ADODB.Field
Dim conn As String
Set c = New ADODB.Connection
With c
.Provider = "sqloledb.1"
With .Properties
    .Item("Data Source") = "Server"
    .Item("Initial Catalog") = "database"
    .Item("PassWord") = "user"
    .Item("User ID") = "pass"
End With
.Open
Set r = .OpenSchema(adSchemaTables, Array(Empty, Empty, Empty, "TABLE"))
With r
    While Not .EOF
    'Table_Type = Table works
        If (.Fields("TABLE_TYPE") = "View" And .Fields("TABLE_NAME") Like "ZZ_*") Then
                'Do something
        End If
        .MoveNext
    Wend
End With

当您调用 .OpenSchema:

时,您在此处指定了 "TABLE" 的条件
Set r = .OpenSchema(adSchemaTables, Array(Empty, Empty, Empty, "TABLE"))

这会过滤表的结果集,因此在您的循环中 .Fields("TABLE_TYPE") 将始终为 "TABLE"(另请注意,它始终为大写)。将过滤器更改为 "VIEW"...

Set r = .OpenSchema(adSchemaTables, Array(Empty, Empty, Empty, "VIEW"))

...然后删除循环中的冗余测试:

If .Fields("TABLE_NAME") Like "ZZ_*" Then
        'Do something
End If