Get tables / schemas from access database 97

I have an Access 97 database in which I am trying to get the data schema and data from. I do not know how many tables are or what they are called, as well as column names.

I have no problem with database access software, but how do you discover the schema?

I use this to get the schema table:

static DataTable GetSchemaTable(string connectionString)
{
    using (OleDbConnection connection = new OleDbConnection(connectionString))
    {
        connection.Open();
        DataTable schemaTable =
            connection.GetOleDbSchemaTable(OleDbSchemaGuid.Tables,
            new object[] { null, null, null, "TABLE" });
        return schemaTable;
    }
}
+4
source share
2 answers

GetOleDbSchemaTablewith OleDbSchemaGuid.Tablesfield returns tables (including name names) defined inside the directory, while an array of objects refers to this construct

new object { "table_catalog", "table_schema", "table_name", "table_type" }

OleDbSchemaGuidIt consists of three fields: OleDbSchemaGuid.Tables, OleDbSchemaGuid.Columnsand OleDbSchemaGuid.Primary_Keys. To get table properties, you can use the field OleDbSchemaGuid.Columns:

connection.GetOleDbSchemaTable(OleDbSchemaGuid.Columns,
        new object[] { "table_catalog", "table_schema", "table_name", "column_name" });

, :

var columns = connection.GetOleDbSchemaTable(OleDbSchemaGuid.Columns,
        new object[] { null, "schema_name", null, null });

, :

var columns = connection.GetOleDbSchemaTable(OleDbSchemaGuid.Columns,
        new object[] { null, "schema_name", "table_name", null });
+1

GetOleDbSchemaTable, :

    DataTable schemaColumns =
        connection.GetOleDbSchemaTable(OleDbSchemaGuid.Columns,
        new object[] { null, "MyTableName", null, null });

whith OleDbSchemaGuid , ,

, , exmaple , . - ,

+1

Source: https://habr.com/ru/post/1690819/


All Articles