C # How to obtain Excel Architecture Information

Source: Internet
Author: User

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 table

EachOleDbSchemaGuidThe 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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.