Create an MDB File

Source: Internet
Author: User

Yesterday, Ling Hu said he needed to use an Access database and did not want to install the office. He asked for solutions in the group.

I suggest using SQL Explorer that comes with Delphi/BCB to connect to the ACCESS database through BDE over ODBC, so that you can modify the database structure and use SQL statements to perform most database operations.

However, one problem is that you cannot create an empty database file and can only connect to an existing MDB file.

However, this problem is well solved. Using ADOX is just a few lines of code. If vbs is the best, of course, there is a ready-made code in msdn. Unfortunately, I will not, so I have to write one with tcx:

Void createmdb (ansistring sfilename)
{
// From msdn
// Create method example (VB)
// The following code shows how to create a new Microsoft JET database with the create method.
Variant adocat;
Widestring connstr = "provider = 'Microsoft. Jet. oledb.4.0 '; Data Source = '"
+ Sfilename + "'";
Procedure createcat ("CREATE ");

Coinitialize (null );
Adocat = variant: Createobject ("ADOX. catalog ");
Adocat. Exec (createcat <connstr );
Couninitialize ();
}

If you use Delphi to write the code, this code will be simpler, Because delphi extends the "." operator function at the compiler level, unlike tcx, which requires the C ++ syntax to remain unchanged.

Download the complete code and compiled programs here: Download Page.

 

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.