C # create an Access database and table

Source: Internet
Author: User

1: Solution Explorer --> reference --> (right-click) Add reference --> com --> Microsoft ADO Ext. 2.8 for DDL and security

2. Create a database

String dbname = @ "D: \ newaccess. mdb ";
ADOX. catalogclass access = new ADOX. catalogclass ();
Access. Create ("provider = Microsoft. Jet. oledb.4.0; Data Source =" + dbname + ";");

3: Create a table

// Create a table
ADOX. tableclass TBL = new ADOX. tableclass ();
TBL. parentcatalog = cat;
TBL. Name = "userinfo ";

// 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 = "uid ";
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 );

TBL = NULL;
Cat = NULL;


Related Article

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.