Automatically copy the original record when data is entered

zhaozj2021-02-17  49

During the data entry process of the database application system, there is a lot of repetition data between each record. If each record makes all the recorded personnel, the repetitive labor is quite large, which is lowered to reduce productivity and appear. Our software is not "professional". In fact, we can use code to implement the automatic copy of database table records. When the customer enters a new record, we can copy the current recorded data to the input box of the entry interface, customers only need to do very few modifications. After completing a new record editor, then save it directly. The examples of this article use Delphi 5.0, using the ADO method to access table test in the Access database, the first field of the table is the "Auto Encoding" field, and jumps when recording replication. The database related components such as AdoConnection1, Adodataset1, DataSource1, DBGRID1 are added to FORM1. Use the Connection Wizard to connect the adoConnection1 to the Access database, set the loginprompt property of AdoConnection1 to false, and the corresponding attribute of other components is set as follows: adodataset1.connection: = AdoConnection1; adodataset1.commandtext: = 'selection * from test'; adodataset1.active: = true; datasource1.dataset: = adodataset1; dbgrid1.datasource: = Datasource1; This, you can see Database Table Test in DBGRID. Data. You can then add some data-sensitive data input controls (such as DBEDIT, etc.) on the form, and set it to DataSource1, and then bind them with each field. Add 2 buttons button1 and button2 on the form, their trigger events are as follows: Procedure TFORM1.BUTTON1CLICK (Sender: TOBJECT); VAR strlist: tstringlist; // Declaration string list i: integer; begin strlist: = tstringlist. Create; for i: = 0 to adodataset1.fieldcount-1 do strlist.add (adodataset1.fields [i] .sstring); // Save the value of each field to TStringList. Unable to apply an array, // Because the array cannot save different types of data. Adodataset1.insert; // Insert a new record for i: = 1 to form1.adodataset1.fieldcount-1 do adodataset1.fields [i] .sstring: = strlist [i]; // Write the data in tstringlist back to the new In the record. // Note that the subscript of TSTRINGLIST starts from 1, skip the "Auto Encoding" field of the table. Strlist.free;

Procedure TForm1.Button2Click (Sender: TOBJECT); begin adodataset1.post; // Save the new record end; After the program is compiled, press the Button1 button, add a new record, the recorded content is the recorded record pointer to the record pointer Content. We can make some changes to existing data, then press the Button2 button to save the new record. The instructions for the program are in the code. Zhang Qing Email: zhangking@263.net phone: 13152101936 QQ: 9365822 http://soft.why100000.com 2003.8.18

转载请注明原文地址:https://www.9cbs.com/read-28932.html

New Post(0)