[C Builder / Delphi Beginner Guide] Three-second Second Complete Data Table Conversion
Xi'an Warton
When the author reads the program, the author often encounters the conversion problem of the database. The general method is to remove the data from the table with the SQL statement, then INSERT to another table. This method is common to use in any programming language. But this is more troublesome, and you need to have some experience.
After using C Builder and Delphi, the author found that the BatchMove control they provided will complete the conversion of the data sheet. And the operation is quite convenient, it can be completed within minutes!
Below, I will do an experiment: convert the Customer.db in the BCDemos (Paradox Library, CB, Delphi) to Test.MDB (Microsoft Access Library).
1. Establish a new project and choose New-àapplication;
2. Add control: Table1, Tabel2, DataSource1, DataSource2, DBGRID1, DBGRID2, BATCHMOVE1, Button1, Button2
3. Create a MDB file, open the file, create a new table, the field only writes only a CustNo, the type is a number (here is the Acess's MDB file database, the field is not used as the paradox table, as long as the first field is the same, or As long as there is a empty table, you can configure ODBC for the file. The author is D: /Test.mdb (the author's ODBC DSN is set to Access, the database is: d: /test.mdb, as shown below :).
4. New a database aller name in the C Builder / Delphi SQL Explorer: Access, and selects its ODBC DSN as the ODBC data source set.
5. Setting attributes for each control (just set on the control, no need to write in the code):
Table1
Table1: TTable Active = True DatabaseName = 'BCDEMOS' TableName = 'customer.db' Table2 Table2: TTable DatabaseName = 'ACCESS' TableName = 'test' TableType = tDefault DataSource1 DataSource1: TDataSource DataSet = Table1 DataSource2 DataSource2: TDataSource DataSet = Table2 BatchMove1 BatchMove1: TBatchMove Destination = Table2 mode = batCopy // very important, indicating that the copy mode Source = Table1 DBGrid2 DBGrid2: TDBGrid DataSource = DataSource1 DBGrid1 DBGrid1: TDBGrid DataSource = DataSource2 Button1 Button1: TButton Caption = 'conversion' Button2 Button2: TButton Caption = 'Refreshing'
6. Add events for Button1 and Button2:
Void __fastcall tform1 :: button1click (TOBJECT * Sender) {
BatchMove1-> execute (); // Execute conversion
}
Void __fastcall tform1 :: button2click (Tobject * Sender)
{
Table2-> open (); // Open the table, you can see the result of the conversion in dBGRID2
}
Finally, program and run the program, click Button1 and other programs, click Button2, you will find that the data in the Customer.db in the Paradox library is imported into the Test table of the Access library Test.mdb.
Using this method is quite simple, just simply set a few related nature, OK, interested friends may try it. (This test program is completed in Windows XP Home Edition, C Builder 6)