OleDbConnection.GetOleDbSchemaTable(Guid, Object[]) 方法

定义

应用了指定的限制之后,按照 GUID 的指示从数据源返回架构信息。Returns schema information from a data source as indicated by a GUID, and after it applies the specified restrictions.

public:
 System::Data::DataTable ^ GetOleDbSchemaTable(Guid schema, cli::array <System::Object ^> ^ restrictions);
public System.Data.DataTable GetOleDbSchemaTable (Guid schema, object[] restrictions);
member this.GetOleDbSchemaTable : Guid * obj[] -> System.Data.DataTable
Public Function GetOleDbSchemaTable (schema As Guid, restrictions As Object()) As DataTable

参数

schema
Guid

OleDbSchemaGuid 的值之一,它指定要返回的架构表。One of the OleDbSchemaGuid values that specifies the schema table to return.

restrictions
Object[]

限制值的 Object 数组。An Object array of restriction values. 这些值按照限制列的顺序来应用。These are applied in the order of the restriction columns. 即:第一个限制值应用到第一个限制列,第二个限制值应用到第二个限制列,依此类推。That is, the first restriction value applies to the first restriction column, the second restriction value applies to the second restriction column, and so on.

返回

一个包含所请求的架构信息的 DataTableA DataTable that contains the requested schema information.

异常

指定的限制集无效。The specified set of restrictions is invalid.

OLE DB 提供程序不支持指定的架构行集合。The specified schema rowset is not supported by the OLE DB provider.

- 或 --or- schema 参数包含 DbInfoLiterals 的值,restrictions 参数包含一条或多条限制。The schema parameter contains a value of DbInfoLiterals and the restrictions parameter contains one or more restrictions.

示例

下面的示例返回数据库中表的列表。The following sample returns a list of tables in a database.

static DataTable GetSchemaTable(string connectionString)
{
    using (OleDbConnection connection = new 
               OleDbConnection(connectionString))
    {
        connection.Open();
        DataTable schemaTable = connection.GetOleDbSchemaTable(
            OleDbSchemaGuid.Tables,
            new object[] { null, null, null, "TABLE" });
        return schemaTable;
    }
}
Public Function GetSchemaTable(ByVal connectionString As String) _
    As DataTable

    Using connection As New OleDbConnection(connectionString)
        connection.Open()

        Dim schemaTable As DataTable = _
            connection.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, _
            New Object() {Nothing, Nothing, Nothing, "TABLE"})
        Return schemaTable
    End Using
End Function

注解

架构表作为 DataTable 返回,其格式与 schema 参数指定的 OLE DB 架构行集的格式相同。The schema table is returned as a DataTable that has the same format as the OLE DB schema rowset specified by the schema parameter. 使用 restrictions 参数可以筛选要在 DataTable 中返回的行(例如,通过指定表名称、类型、所有者或架构的限制)。Use the restrictions parameter to filter the rows to be returned in the DataTable (for example, by specifying restrictions for table name, type, owner, or schema). 在数组中传递值时,为不包含值的数组元素包含空字符串或 null 值。When you pass values in the array, include empty strings or nulls for array elements that do not contain values. 如果将一个空数组传递到 restrictions,则按默认顺序返回所有行(每个表一个)。If you pass an empty array to restrictions, all rows (one for each table) are returned in default order. 数组中的值对应于源表中的列顺序和 DataTableValues in the array correspond to the order of the columns in the source table and DataTable. 限制数组中的每个元素都与架构行集中相应列的内容进行比较。Each element in the restrictions array is compared with the content of the corresponding column in the schema rowset. 例如,限制数组中的第一个元素与行集中的第一列进行比较。For example, the first element in the restrictions array is compared to first column in the rowset. 如果限制元素不为 null,则只会将架构行集中与限制的值完全匹配的行添加到生成的 DataTable中。If a restriction element is not null, only rows from the schema rowset that exactly match the value of the restriction are added to the resulting DataTable.

OleDbConnection 方法使用标准公共语言运行时转换规则调用基础 OLE DB IDBSchemaRowset:: GetRowset方法。The OleDbConnection method calls the underlying OLE DB IDBSchemaRowset::GetRowset method using standard common language runtime conversion rules. 有关详细信息,请参阅COM 数据类型For more information, see COM Data Types.

您可以使用 DbInfoLiterals检索有关文本的信息。You can retrieve information about literals by using DbInfoLiterals. 此方法提供与调用 OLE DB IDBInfo:: GetLiteralInfo接口或 ADO OpenSchema方法与 adSchemaDBInfoLiterals 常数等效的信息。This provides information equivalent to calling the OLE DB IDBInfo::GetLiteralInfo interface, or the ADO Connection.OpenSchema method with the adSchemaDBInfoLiterals constant.

适用于

另请参阅