Because ADOX is used in the program, you must first reference it in the solution as follows:
Solution Explorer --> reference --> (right-click) Add reference --> com --> Microsoft ADO Ext. 2.8 for DDL and security
Private void btncreate_click (Object sender, eventargs E)
{
String dbname = "E: \ temp \" + datetime. Now. millisecond. tostring () + ". mdb ";
ADOX. catalogclass cat = new ADOX. catalogclass ();
Cat. Create ("provider = Microsoft. Jet. oledb.4.0; Data Source =" + dbname + ";");
MessageBox. Show ("Database:" + dbname + "already created! ");
// Create a table
ADOX. tableclass TBL = new ADOX. tableclass ();
TBL. parentcatalog = cat;
TBL. Name = "mytable ";
// Add an Automatically increasing field
ADOX. columnclass Col = new ADOX. columnclass ();
Col. parentcatalog = cat;
Col. type = ADOX. datatypeenum. adinteger; // you must set the field type first.
Col. Name = "ID ";
Col. properties ["jet oledb: Allow zero length"]. value = false;
Col. properties ["autoincrement"]. value = true;
TBL. Columns. append (COL, ADOX. datatypeenum. adinteger, 0 );
// Add a text field
ADOX. columnclass col2 = new ADOX. columnclass ();
Col2.parentcatalog = cat;
Col2.name = "Description ";
Col2.properties ["jet oledb: Allow zero length"]. value = false;
TBL. Columns. append (col2, ADOX. datatypeenum. advarchar, 25 );
Cat. Tables. append (TBL); // Add the table to the database (very important)
MessageBox. Show ("database table:" + TBL. Name + "already created! ");
TBL = NULL;
Cat = NULL;
}