Category: vs2003 C # Application
---------------------------
Data_type list
Note: 130
String 130
Date: 7
Number: 3
---------------------------
Obtain all tables
DB = new dB (this. textbox1.text );
System. Data. datatable schematable = dB. oleconnection. getoledbschematable (system. Data. oledb. oledbschemaguid. Tables, new object [] {null, "table "});
Arraylist Ss = new arraylist ();
For (INT I = 0; I <schematable. Rows. Count; I ++)
{
SS. Add (schematable. Rows [I]. itemarray [2]. tostring ());
}
This. listbox1.datasource = SS;
// System. Windows. Forms. MessageBox. Show (tablenames );
DB. Close ();
------------------------------
Obtain all fields
// System. Windows. Forms. MessageBox. Show (this. listbox1.selectedvalue. tostring ());
DB = new dB (this. textbox1.text );
System. data. datatable schematable = dB. oleconnection. getoledbschematable (system. data. oledb. oledbschemaguid. columns, new object [] {null, null, this. listbox1.selectedvalue. tostring (), null });
Arraylist Ss = new arraylist ();
// This shows the attributes of the Table: used to obtain the table .. Because oledbschemaguid. Tables is changed to oledbschemaguid. columns ..
// For (INT I = 0; I <schematable. Columns. Count; I ++)
//{
// Ss. Add (schematable. Columns [I]. tostring ());
//}
// This is for displaying Columns
For (INT I = 0; I <schematable. Rows. Count; I ++)
{
SS. add (schematable. rows [I]. itemarray [3]. tostring () + ":" + schematable. rows [I]. itemarray [11]. tostring ());
}
This. listbox2.datasource = SS;
// System. Windows. Forms. MessageBox. Show (tablenames );
DB. Close ();
-----------------------------------------
DB type
Public oledbconnection oleconnection;
Public dB (string connstring)
{
Try
{
Connstring = "provider = Microsoft. Jet. oledb.4.0; Data Source =" + connstring;
Oleconnection = new oledbconnection (connstring );
Oleconnection. open ();
// System. Windows. Forms. MessageBox. Show ("the database is connected! ");
}
Catch
{
System. Windows. Forms. MessageBox. Show ("database connection error! ");
}
}
Public void close ()
{
Oleconnection. Close ();
// System. Windows. Forms. MessageBox. Show ("the database is disabled! ");
}
-----------------------------------
Reference 1:
How to read the table structure information of the Access Database
Http://www.why100000.com/Htmls/tabAspNet213.htm
Reference 2:
C # Use getoledbschematable to retrieve Architecture Information (tables, columns, primary keys, etc)
Http://www.cnitblog.com/yhf119/archive/2008/01/16/38926.html