1. dynamically create a table structure, introduce two dynamic libraries in com, one is ADOX, the other is ADODB, and the other is ADOX. dll and Interop. ADODB. dll2. Add a button in wfm. The button event is as follows: m_path is the path of the current program running. You can write an absolute path, which is a relative path. Privatevoidbutton#click (objectsend
1. dynamically create a table structure, introduce two dynamic libraries in com, one is ADOX, the other is ADODB, and the other is ADOX. dll and Interop. ADODB. dll 2. add a button in wfm. The button event is as follows: m_path is the path of the current program running. You can write absolute paths, which are relative paths. Private void button#click (object send
1. dynamically create the table structure and introduce two dynamic libraries in com. One is ADOX and the other is ADODB. dll, ADOX. dll and Interop. ADODB. dll.
2. Add a button in wfm. The button event is as follows:
M_path is the path of the current program running, which can be an absolute path. It is a relative path.
Private void button#click (object sender, EventArgs e)
{
String strdb = m_path + "\ DomTest. mdb ";
If (File. Exists ("" + strdb + "") // first checks whether the database Exists. if not, create
{
MessageBox. Show ("the current database exists. Please delete it first", "message prompt ");
Return;
}
ADOX. Catalog catalog = new Catalog ();
Catalog. Create ("Provider = Microsoft. Jet. OLEDB.4.0; Data Source = '" + strdb + "'; Jet OLEDB: Engine Type = 5 ");
ADODB. Connection cn = new ADODB. Connection ();
Cn. Open ("Provider = Microsoft. Jet. OLEDB.4.0; Data Source = '" + strdb + "'", null, null,-1 );
Catalog. ActiveConnection = cn;
ADOX. Table table = new ADOX. Table ();
Table. Name = "Table1 ";
ADOX. Column column = new ADOX. Column ();
Column. ParentCatalog = catalog;
Column. Name = "RecordId"; // column Name
Column. Type = DataTypeEnum. adInteger; // column data Type
Column. DefinedSize = 9; // size
Column. Properties ["AutoIncrement"]. Value = true; // whether the attribute is automatically added
Table. Columns. Append (column, DataTypeEnum. adInteger, 9); // Add the first column
Table. Keys. Append ("TablePrimaryKey", KeyTypeEnum. adKeyPrimary, column, null, null );
Table. Columns. Append ("Name", DataTypeEnum. adVarWChar, 50); // Add the second column
Table. Columns. Append ("Age", DataTypeEnum. adInteger, 9); // Add the third column
Table. Columns. Append ("Birthday", DataTypeEnum. adDate, 0); // Add the fourth column
Catalog. Tables. Append (table); // Add the current table
Cn. Close ();
MessageBox. Show ("the database is created successfully and its location is stored in" + m_path, "");
}