Create an Access database and table using Adox

zhaozj2021-02-11  207

Using system; using adox;

Summary description of Namespace Webportal {///

/// createaccessdb. /// For different versions of ADO, you need to add different references /// Please add a reference Microsoft Ado ext. 2.7 for DDL and security /// Please add a reference Microsoft Ado ext. 2.8 for DDL and security /// Public class create createAccessdb: system.Web.ui.page {private void page_load (Object sender, system.eventargs e) {// For easy testing, the database name uses a relatively random name to prevent it from adding unsuccessful, it needs to be restarted. IIS to delete the database. String dbname = "d: // newmdb" DateTime.now.millisecond.toString () ".mdb"; adox.catalogclass cat = new adox.catalogclass (); cat.create ("provider = microsoft.jet.oledb .4.0; Data Source = " DBNAME "; "); response.write (" Database: " DBNAME " has created success! "); Adox.tableclass tbl = new adox.tableclass (); tbl.parentCatalog = Cat; tbl.name = "myTable";

// Add an automatic growth field adox.columnclass color (); col.parentCatalog = cat; col.Type = adox.DataTypeenum.adinteger; // must set the field type col.name = "id" Col.properties ["Jet OLEDB: Allow Zero Length"]. Value = false; col.properties ["autoincrement"]. Value = true; tbl.columns.Append (col, adox.dattypeenum.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.dattypeenum.advarchar, 25);

// Set the primary key tbl.keys.append ("PrimaryKey", Adox.Keytypeenum.adkeyPrimary, "ID", "", ""); Cat.Tables.Append (TBL); response.write ("
database table : " TBL.Name " has been created! "); Tbl = null; Cat = null;}

#Region Web Form Designer Generated Code Override Protected Void OnNit (Eventargs E) {// // Codegen: This call is required for the ASP.NET Web Form Designer. // InitializeComponent (); base.oninit (e);

///

/// Designer supports the required method - do not use the code editor to modify the // / this method. /// private void initializecomponent () {this.load = new system.eventhandler (this.page_load);} #ENDREGON}}

转载请注明原文地址:https://www.9cbs.com/read-5408.html

New Post(0)