This documentation is archived and is not being maintained.

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
public DataTable GetOleDbSchemaTable(
 Guid schema,
 object[] restrictions
public: DataTable* GetOleDbSchemaTable(
 Guid schema,
 Object* restrictions __gc[]
public function GetOleDbSchemaTable(
   schema : Guid,
 restrictions : Object[]
) : DataTable;


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


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.


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


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.


[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
  Dim schemaTable As DataTable = conn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, _
                                                          New Object() {Nothing, Nothing, Nothing, "TABLE"})
  Return schemaTable
End Function

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

    DataTable* GetTables(OleDbConnection* conn)
        Object* restrictions[] = {0, 0, 0, S"TABLE"};
        DataTable* schemaTable = conn->GetOleDbSchemaTable(OleDbSchemaGuid::Tables, restrictions);
        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.


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