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.