Delphi adoquery processing Multiple SQL statements

Source: Internet
Author: User

Tag: des io os ar for SP data on issue

Delphi (Pascal) code
Var
sqlstr:string;
Begin
sqlstr:= ' Begin '
sqlstr:= sqlstr+ ' Update table1 set col1 = ' Test ' where 1=2; ';
sqlstr:= sqlstr+ ' Update table1 set col1 = ' test2 ' where 1=2; ';
sqlstr:= sqlstr+ ' End ';

Adoquery1. Close;
Adoquery1. Sql. Clear;
Adoquery1. Sql. ADD (SQLSTR);
Adoquery1. Execsql;
End

The SQL statement with Begin...end Wrap, and then submitted to the DB processing, OK!

Adoquery Batch processing method
For example, in a form there is a "cancel" and "OK" button, "Cancel" button batch cancel all changes, "OK" button batch submission:
1. Set the LockType for Qrydef (dataset) to Ltbatchoptimistic,cursortype to Ctstatic,cursorlocation for cluseclient
2. The Click event for the OK button is:
If QryDef.Connection.InTransaction Then
Begin
Try
Qrydef.updatebatch ();
QryDef.Connection.CommitTrans;
Except
QryDef.Connection.RollbackTrans;
End
End
3. The Click event for the Cancel button is:
Qrydef1.cancelbatch;
4. Initial Insert Data:
Qry.loadfromfile (Extractfilepath (application.exename) + ' classifydefine ');
{$IFDEF test}codesite. Sendmsg (' 3 '); {$ENDIF}
While not qry.eof do
Begin
Qrydef.append;
Qrydef.fieldbyname (' name '). Asstring: = Qry.fieldbyname (' name '). asstring;
If not qry.fieldbyname (' Money1 '). IsNull Then
Qrydef.fieldbyname (' Money1 '). Ascurrency: = Qry.fieldbyname (' Money1 '). ascurrency;
If not qry.fieldbyname (' Money2 '). IsNull Then
Qrydef.fieldbyname (' Money2 '). Ascurrency: = Qry.fieldbyname (' Money2 '). ascurrency;
Qrydef.post;
Qry.next;
End
Qrydef.updatebatch ();

5. Other examples of batch processing methods:

Procedure Tform1.button1click (Sender:tobject);
Begin
Adoconnection1.begintrans;
Try
Adoquery.close;
Adoquery.sql.clear;
Adoquery.sql.add (insert statement);
Adoquery.execsql;
If you have an INSERT statement:
Adoquery.close;
Adoquery.sql.clear;
Adoquery.sql.add (insert statement);
Adoquery.execsql until all INSERT statements are complete.
Adoconnection1.committrans;
Except
Adoconnection1.rollbacktrans;
End
End

Use Adoquery to fetch all value problems for a specified field
I'm going to show it in the Dbcombobox.
While not adoquery1. Eof do
Begin
COMBOBOX1.ITEMS.ADD (adoquery1.fieldbyname (' id '). asstring); Change the ID to the field you want to specify
Adoquery1. Next;
End
Show it in the Dbcombobox.
If it's Dbcombobox,
Procedure Tform1.formcreate (Sender:tobject);
Begin
Adoquery1. Sql. ADD (' SELECT * from Test ');
Adoquery1. Open;
dbcombobox1.datafield:= ' id ';
While not adoquery1. Eof do
Begin
DBCOMBOBOX1.ITEMS.ADD (Adoquery1.fieldbyname (Dbcombobox1.datafield). asstring);
Adoquery1. Next;
End
End

Xxx.sql.text: = ' insert into T_log3 (Name,czsj,czlog) VALUES (' ' +a + ', ' ' + B + ', ' ' +c+ ') ';
Or
Xxx.sql.text: = ' insert into T_log3 (Name,czsj,czlog) VALUES (: A1,:B1,:C1) ';
Xxx.parameters.parambyname (' A1 '). Values: = A;
Xxx.parameters.parambyname (' B1 '). Values: = b;
Xxx.parameters.parambyname (' C1 '). Values: = C;

Delphi adoquery processing Multiple SQL statements

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.