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.