The OleDbConnection. GetOleDbSchemaTable method can be used to obtain the Architecture Information of the data source to be retrieved. It is usually used as follows:
DataTable Schemadt = OleDbConnection. GetOleDbSchemaTable (OleDbSchemaGuid. Tables, new [] {null, "table "});
View data in Schemadt
For (int I = 0; I <Schemadt. Rows. Count; I ++)
{
Console. WriteLine ("SheetName =" + Schemadt. Rows [I] ["TABLE_NAME"]. ToString ());
}
Note:SqlClient. SqlConnectionThe object does not matchGetOleDbSchemaTableEquivalent method.
The following describes the GetOleDbSchemaTable method.
Use the ole db. NET data providerOleDbConnectionObjectGetOleDbSchemaTableMethod to display the architecture information.GetOleDbSchemaTableReturnsDataTable.
GetOleDbSchemaTableThe first parameter is the architecture parameter, which isOleDbSchemaGuidSpecifies the type of schema information to be returned (such as tables, columns, and primary keys ). The second parameter is an array of restricted objects.DataTableThe Rows returned in the schema are filtered (for example, you can specify the table name, type, owner, and/or schema restrictions ).
OleDbSchemaGuid Member
OleDbSchemaGuid parameter specifiedGetOleDbSchemaTableThe type of the schema table to be returned.
OleDbSchemaGuid members include:
• Columns • Foreign keys • indexes • Primary keys • Tables • Views
Restrictions
The limit is an array of filtered value objects. Each element corresponds to the result.DataTableOneDataColumn.OleDbSchemaGuidParameters determine the corresponding limits. For exampleOleDbSchemaGuidThe limit array is as follows:
{TABLE_CATALOG, TABLE_SCHEMA, TABLE_NAME, TABLE_TYPE}
When passing the limit array value, use the Visual C #. NETNullKeyword. For example, if you want to retrieve the structure of a table, useOleDbSchemaGuid. Tables. However, if a table is specified, aliases, synonyms, views, and other related objects are returned. Therefore, if you want to filter out all objects except the TABLE, use TABLE restrictions on TABLE_TYPE. You can use TABLE_CATALOG, TABLE_SCHEMA, and TABLE_NAMENullBecause you do not filter these objects:schemaTable = cn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables,
new Object[] {null, null, null, "TABLE"});
Returned data tableEachOleDbSchemaGuidThe object of the type and restriction rule correspondsGetOleDbSchemaTableMethod returnDataTable. Each limit column correspondsDataTableIs followed by a column based onOleDbSchemaGuidOther Architecture Information of the field.
For example, if you use the following codeDataTableOf