Export (0) Print
Expand All

OleDbConnection.GetOleDbSchemaTable Method

Returns schema information from a data source as indicated by a GUID, and after applying the specified restrictions.

[Visual Basic]
Public Function GetOleDbSchemaTable( _
   ByVal schema As Guid, _
   ByVal restrictions() As Object _
) As DataTable
[C#]
public DataTable GetOleDbSchemaTable(
 Guid schema,
 object[] restrictions
);
[C++]
public: DataTable* GetOleDbSchemaTable(
 Guid schema,
 Object* restrictions __gc[]
);
[JScript]
public function GetOleDbSchemaTable(
   schema : Guid,
 restrictions : Object[]
) : DataTable;

Parameters

schema
One of the OleDbSchemaGuid values that specifies the schema table to return.
restrictions
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.

Return Value

A DataTable containing the requested schema information.

Exceptions

Exception Type Condition
OleDbException The specified set of restrictions is invalid.
InvalidOperationException The OleDbConnection is closed.
ArgumentException The specified schema rowset is not supported by the OLE DB provider.

or

The schema parameter contains a value of DbInfoLiterals and the restrictions parameter contains one or more restrictions.

Remarks

The schema table is returned as a DataTable that has the same format as the OLE DB schema rowset specified by the the schema parameter. Use the restrictions parameter to filter the rows to be returned in the DataTable (for example, by specifying restrictions for tablename, type, owner, or schema). When you pass values in the array, include empty strings or nulls for array elements that do not contain values. If you pass an empty array to restrictions, all rows (one for each table) are returned in default order. Values in the array correspond to the order of the columns in the source table and DataTable. Each element in the restrictions array is compared to 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. 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.

The OleDbConnection method calls the underlying OLE DB IDBSchemaRowset::GetRowset method using standard common language runtime conversion rules. For more information, see COM Data Types.

You can retrieve information about literals by using DbInfoLiterals, which provides information equivalent to calling the OLE DB IDBInfo::GetLiteralInfo interface, or the ADO Connection.OpenSchema method with the adSchemaDBInfoLiterals constant.

Example

[Visual Basic, C#, C++] The following sample returns a list of tables in a database.

[Visual Basic] 
Public Function GetTables(conn As OleDbConnection) As DataTable
  conn.Open()
  Dim schemaTable As DataTable = conn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, _
                                                          New Object() {Nothing, Nothing, Nothing, "TABLE"})
  conn.Close()
  Return schemaTable
End Function

[C#] 
public DataTable GetTables(OleDbConnection conn)
{
  conn.Open();
  DataTable schemaTable = conn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables,
                                                   new object[] {null, null, null, "TABLE"});
  conn.Close();
  return schemaTable;
}

[C++] 
public:
    DataTable* GetTables(OleDbConnection* conn)
    {
        conn->Open();
        Object* restrictions[] = {0, 0, 0, S"TABLE"};
        DataTable* schemaTable = conn->GetOleDbSchemaTable(OleDbSchemaGuid::Tables, restrictions);
        conn->Close();
        return schemaTable;
    };

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.

Requirements

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family

See Also

OleDbConnection Class | OleDbConnection Members | System.Data.OleDb Namespace | OleDbSchemaGuid

Show:
© 2014 Microsoft