Obtain all the table names and column names in the ACCESS database in C #.

Source: Internet
Author: User

We often want to obtain all the table names and column names in a database. SQL MS Medium, convenient, direct query Sysobjects Table. However Access , How to get it? There was one yesterday.ProgramTo use Access To determine whether the table exists. If the table does not exist, it is created.

 

It's actually very simple. We use. NetBuilt-in methods can be obtained.

AccessAccessThe database I use isOledb.CodeAs follows:

 

Sqlconn. getoledbschematable (oledbschemaguid. Tables, new object [] {null, "table "});

 

This code returns the list of all data tables in the database. The returned value isDatatable, You can bindDataGridTo view its internal data structure. To obtain the content you need.

WhereSqlconnIs an openedOledbData Connection instance.

 

Sqlconn. getoledbschematable (oledbschemaguid. columns, new object [] {null, null, strtablename, null });

 

This code returns a list of data columns in the specified data table. The returned value isDatatable, You can bind thisDataGridTo view its internal data structure and obtain the specific content you need.

WhereSqlconnIs an openedOledbData Connection instance. ParametersStrtablenameIs the name of the specified data table.

 

Okay. Try it now. For more information, seeMsdnBecause of these thingsMsdn.

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.