Use. NET to obtain the schema of the OLE DB database.

Source: Internet
Author: User
Tags count ole tostring
Architecture | data | Databases get information about SQL Server databases you can use the DMO component or directly obtain information about the system tables, such as tables, views, stored procedures, and so on sysobjects tables where the information in the column exists syscolumns table. If you want to get information about an OLE DB database, such as Access's database.

You first reference the COM components Microsoft ActiveX Data Object 2.x Library and Microsoft ADO Ext. 2.x for DDL ...
The following is the C # code:

String strconnection = "Provider=Microsoft.Jet.OLEDB.4.0;Data source=" C:\\TEST.MDB;

ADODB. Connection conn = new ADODB. Connectionclass ();
Conn. ConnectionString = strconnection;

Conn. Open (strconnection, "Admin", "" ", 0);


ADOX. Catalog CTG = new ADOX. Catalogclass ();
Ctg.let_activeconnection (conn);

Get tables info from OLE DB database
for (int i = 0; i < CTG.) tables.count-1; i++)
{
Console.WriteLine (CTG). tables[i]. Name);
}

Get columns information from a table named Test.
ADOX. Table table = CTG. tables["Test"];
for (int i = 0; i < table. columns.count-1; i++)
{
ADOX. Column column = table. columns[i];
Console.WriteLine (column. Name + "\ T" + columns. Type.tostring () + column. Defaultsize.tostring ());
}


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.