The original record is automatically copied during data entry.

Source: Internet
Author: User
During the data entry process of the database application system, a large amount of duplicate data exists between each record. If each record is manually input by all the entry personnel, the repetitive work during the record is quite large, it not only reduces the work efficiency, but also shows that our software is not "professional ". In fact, we can use code to automatically copy database table records.

During the data entry process of the database application system, a large amount of duplicate data exists between each record. If each record is manually input by all the entry personnel, the repetitive work during the record is quite large, it not only reduces the work efficiency, but also shows that our software is not "professional ". In fact, we can use code to automatically copy database table records.

During the data entry process of the database application system, a large amount of duplicate data exists between each record. If each record is manually input by all the entry personnel, the repetitive work during the record is quite large, it not only reduces the work efficiency, but also shows that our software is not "professional ".
In fact, we can use code to automatically copy database table records. When a customer enters a new record, we can copy the data of the current record to the input boxes on the input interface, the customer only needs to make few changes to complete the editing of a new record, and then save it directly.
The example in this article is made using Delphi5.0 and the ADO method is used to Access the test table in the Access database. The first field of the table is the "Automatic encoding" field, which must be skipped during record replication. Add database-related components such as ADOConnection1, ADODataSet1, DataSource1, and DBGrid1 on Form1, use the Connection Wizard to connect ADOConnection1 to the Access database, and set the LoginPrompt attribute of ADOConnection1 to False, the attributes of other components are set as follows:
ADODataSet1.Connection: = ADOConnection1;
ADODataSet1.CommandText: = 'select * from test ';
ADODataSet1.Active: = True;
Performance1.dataset: = ADODataSet1;
DBGrid1.DataSource: = performance1;
In this way, you can see the data in the database table test in DBGrid.
Then, you can add some data-sensitive data input controls (such as DBEdit) on the form, set the DataSource attribute to performance1, and then bind them with each field.
Then, add two buttons Button1 and Button2 to the form. Their trigger events are as follows:
Procedure TForm1.Button1Click (Sender: TObject );
Var
StrList: TStringList; // declare the string list
I: integer;
Begin
StrList: = TStringList. Create;
For I: = 0 to ADODataSet1.FieldCount-1 do
StrList. Add (ADODataSet1.Fields [I]. AsString );
// Save the values of each field to the TStringList. Array cannot be applied,
// Because arrays cannot store different types of data.
ADODataSet1.Insert; // Insert a new record
For I: = 1 to form1.ADODataSet1. FieldCount-1 do
ADODataSet1.Fields [I]. AsString: = strList [I];
// Write the data in the TStringList back to the new record.
// Note that the subscript of TStringList starts from 1 and the "Automatic encoding" Field of the table is skipped.
StrList. Free;
End;

Procedure TForm1.Button2Click (Sender: TObject );
Begin
ADODataSet1.Post; // Save the new record
End;

After the program is compiled and run, press the Button1 button to add a new record. The record content is the record content pointed to by the record pointer before the addition. We can make some changes to the existing data, and then press the Button2 button to save the new record. Program description in the code.

Zhang Qing Email: zhangking@263.net Phone: 13152101936 QQ: 9365822
Http://soft.why100000.com 2003.8.18

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.