How to obtain all user tables and views in the Access Database

Source: Internet
Author: User

Method 1: perform special processing on database files:
Open Database Files
Tools> options
Then set both the system object and the hidden object:

Then you will see the system table:
The msysobjects table is similar to the system table in sqlserver, which records all user tables, views, and other information. You just need to query it.
SQL statement: "select [name] as [table_name], [flags], [type] from [msysobjects] Where [flags] = 0 and [type] = 1 ";

However, by default, your applicationProgramYou do not have the permission to read this table (yes, you do not have the permission to read this table ).
Therefore, before reading this table, you must set the permissions:
Tools> Security> user and group permissions

Just remove the read permission.

However, we cannot guarantee that all data files have the read permission on msysobjects, And it is troublesome to set it every time.

Method 2:
Use oledb system APIs to solve this problem. Of course, oledbconnection of. net has been encapsulated for us.
Datatable schematable = conn. getoledbschematable (oledbschemaguid. Tables, new object [] {null, "table "});
You can do it with just one sentence. Of course, the view can be read in the same way. For more information, see msdn.

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.