Recently, I encountered data batch processing problems when I was writing a database development module for a good friend.
I have thought about some development methods for data batch processing, and I dare not enjoy a special summary and share it with you.
In database application systems, data is often batched, such as appending, deleting, and changing.
This batch operation is carried with the corresponding commands in special database development tools such as VFP using the APPEND and COPY commands.
Command clauses can be easily completed. However, there are no similar commands in other development tools.
Instead, it provides controls or objects that can complete similar functions, such as in PowerBuilder
Use Pipe Line (data pipeline) to complete data batch processing between two or isomorphic or different-constructed tables.
This article introduces the method of batch processing using Timer components when using Delphi for database development.
In Delphi development, the most used methods are ADO and BDE when using Delphi for database development. As we all know, BDE was once vigorously advocated by Borland.
So Borland spent a lot of experience on BDE components, so there is a TBatchMove control on data batch processing that can complete data batch processing.
The specific operation must be completed by setting the Mode property of TBatchMove and then calling the Execute method. Help with BDE.
The actual results of various operating modes in this article can be found from Delphi's Database Desktop
Viewed in.
This is not the focus of this article, so I will not elaborate on this. If you are interested in the clear comments in the Delphi document, please check it out.
The focus of this article is: batch processing method of data in ADO.
When you get this problem, the general method is to traverse all data and insert it loops.
However, what I want to talk about here is a fast, efficient, and recommended batch processing method. The specific code and operation method are as follows: the basic connection code of the database:
PRocedure TForm1.FormCreate(Sender: TObject);
var
MyPath:string;
const
MyPassW ='****'; ///Database Password
Begin
MyPath:=ExtractFilePath(ParamStr(0)); //// Database path
AdoConnection1.ConnectionString :='Provider=Microsoft.Jet.OLEDB.4.0;Data Source='+
MyPath+'db/db.mdb;Jet OLEDB:Database PassWord='+
MyPassW+';Persist Security Info=False';
//////////// Set up the data engine and load the password
ADOConnection1.LoginPrompt := false;
ADOConnection1.Connected := true;
ADOTable1.Connection := ADOConnection1;
ADOTable1.TableName:='tab1';
ADOTable2.Connection := ADOConnection1;
ADOTable2.TableName:='tab2';
try
ADOTable2.Open;
ADOTable1.Open;
DataSource1.DataSet := ADOTable1;
DBGrid1.DataSource := DataSource1;
DBNavigator1.DataSource := DataSource1;
except
MessageBox(0,'Cannot open database','Error',MB_OK);
end;
/////////////////// Timer control control loop
Begin
//////////////////// Batch data processing of heterogeneous tables that perform error control
DataSource2.DataSet.Insert;
ADOTable2.Fields[0].AsString:=ADOTable1.Fields[0].AsString;
ADOTable2.Fields[1].AsString:=ADOTable1.Fields[1].AsString;
DataSource1.DataSet.Next;
if DataSource1.DataSet.Eof = True then timer1.Enabled := false ;
if DataSource1.DataSet.Eof = True then ShowMessage('Data was imported successfully!');
except
MessageBox(0,'Data import failed','Error', MB_OK);
end;
end;
DataModule2.DataSource1.DataSet.Next;////////////////////// This sentence is the most critical, that is, a loop statement.
The time to insert a record (Timer's response time) can be set.
This is the batch import function of data between heterogeneous tables designed by the Timer component's characteristics.DataSet.Next attribute.
Then, similar code can be implemented for deletion, update and other functions (use DataSource attributes to modify).
Because there is query function, I use the TADOQuery component in development, roughly the same method.
Author: VIIVD
E-MAIL:[email protected]
Date: 2004.6.5