Begin end batch operations on applications in Oracle databases

Source: Internet
Author: User
Tags oracleconnection

Batch Oracle operations:

Syntax begin end

UpperCode:

Update_is_defluat

 
1Public Static StringUpdate_is_defluat ="Update neorule set isdefault =: isdefault {0} Where id =: Id {0}";
Front-end code

 1 Dictionary < String , String > Dict = New Dictionary < String , String > ();  2           If ( This . Gv_menu.rows.count <= 0 ){ Return  ;}  3           For ( Int I = 0 ; I < This . Gv_menu.rows.count; I ++ )  4   {  5 Hiddenfield hidid = (hiddenfield) This . Gv_menu.rows [I]. findcontrol ( "  Hidid  "  );  6 Hiddenfield hiddefault = (hiddenfield) This . Gv_menu.rows [I]. findcontrol ( "  Hiddefault "  );  7 Checkbox cbdefault = (checkbox) This . Gv_menu.rows [I]. findcontrol ( "  Chdefault  "  );  8 Dict. Add (hidid. Value, cbdefault. checked? "  T  " : "  F  " );  9   }  10   11 Bll. updateisdefault (dict );
Bll

 1    Public   Static   String Update_is_defluat = "  Update neorule set isdefault =: isdefault {0} Where id =: Id {0}  "  ;  2        # Region Batch database operations 3           ///   <Summary>  4           ///  Batch database operations  5           ///   </Summary>  6           ///   <Param name = "dict"> </param>  7           ///   <Returns> </returns> 8           Public   Bool Updateisdefault (Dictionary < String , String > Dict)  9   {  10 Oracleparameter [] completeparms = New Oracleparameter [dict. Count * 2  ];  11 Stringbuilder query =New  Stringbuilder ();  12               Int Index = 0  ;  13               Int I = 0  ;  14 Query. append ( "  Begin  "  );  15              Foreach (Keyvaluepair < String , String > Item In  Dict)  16   {  17 Completeparms [Index] = New Oracleparameter ( "  : Isdefault  " + I, item. value );  18 Index = index + 1  ;  19 Completeparms [Index] = New Oracleparameter ( "  : ID  " + I, item. Key );  20 Index = index + 1  ;  21 Query. append ( String . Format (update_is_defluat, I ));  22 Query. append ( "  ;  "  );  23 I = I + 1  ;  24   }  25 Query. append ( "  End;  " );  26               Return  Dal. updateisdefaultbyid (query. tostring (), completeparms );  27   }  28           # Endregion 
 1    Public   Bool Updateisdefaultbyid ( String  Query, oracleparameter [] PARAM)  2   { 3              4               Using (Oracleconnection con = New  Oracleconnection (connectionstring ))  5   {  6   Con. open ();  7                   Using (Oracletransaction TRAN = Con. begintransaction ())  8   {  9                      Try  10   {  11 Oraclecommand cmd = Con. createcommand ();  12 Cmd. commandtext = Query;  13 Cmd. Transaction = Tran;  14   Cmd. Parameters. addrange (PARAM );  15  Cmd. executenonquery ();  16   Tran. Commit ();  17                           Return   True  ;  18   }  19                       Catch  (Exception ex)  20   {  21  Tran. rollback ();  22   Log. Error (ex. Message, ex );  23                           Return   False  ;  24   }  25   }  26                   27   }  28 }

 

Related Article

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.