ASP. NET-ROLLBACK TRANSACTION

Source: Internet
Author: User

SqlConnection con =NewSqlConnection (CONNECTIONDB.CONSTR);//Get database connectionCon. Open ();//Open ConnectionSqlTransaction Sqltra = con. BeginTransaction ();//Start a transactionSqlCommand cmd =NewSqlCommand ();//instantiation ofCmd. Connection = con;//Get Data connectionCmd. Transaction = Sqltra;//, when you execute SQL,Try        {            stringsql ="INSERT INTO oa_meeting (meeting_id,meeting_name,meeting_title,start_time,end_time,announce_time,explain,reg_ emp_id,emc_emp_id,par_emp_id,rep_emp_id,participate,meeting_type,proj_id,work_id) VALUES ('"+ ID +"', N '"+ Meetname +"', N '"+ Meettitle +"', '"+ StartTime +"', '"+ Endtime +"', N '"+ Djtime +"', N '"+ Meetinfo +"', '"+ Empid +"', '"+ Meetperson +"', '"+ lname +"', '"+ writer +"', '"+ CCName +"', '"+ Hidsort. Value +"', '"+ Proid +"', '"+ WorkID +"')"; Cmd.commandtext=SQL; Cmd.            ExecuteNonQuery (); //string meetid = ID;intSize =0; Httpfilecollection Files=HttpContext.Current.Request.Files; //traverse the upload file form all HTML controlsforeach(stringNameIdinchrequest.form) {//Find the File description text box with the first four bits "Txt_" for the control ID nameif(Nameid.substring (0,4) =="ttx_")                {                    //Get text descriptionif(Request.form[nameid]! ="")                    {                        stringExplain = Request.form[nameid];//Get txt text descriptionhttppostedfile Pstfile= files["Fil_"+ nameid.substring (4)]; stringFileName =""; stringFileExtension =""; FileName= System.IO.Path.GetFileName (pstfile. FileName);//full name of uploaded fileFileExtension = System.IO.Path.GetExtension (fileName);//Extended NamestringNewName = Filename.remove (Filename.lastindexof ("."));//Remove the filename of the suffix namestringSQL1 ="Select IsNull (max (app_id), 0) from Oa_meeting_appendix"; intIDD = Convert.ToInt32 (objconnction.getstring (SQL1)) +1; Ua. Folder_exists (" Meeting"); stringfilepath =".. \\AtthFiles\\Meeting\\Meeting_"+ IDD. ToString () +fileextension; stringSQLSTR1 ="INSERT INTO Oa_meeting_appendix (App_id,meeting_id,explain,app_path) VALUES ('"+ IDD +"', '"+ ID +"', N '"+ Explain +"', N '"+ filepath +"')"; Cmd.commandtext=sqlstr1; intnum =cmd.                        ExecuteNonQuery (); if(Num >0) {Pstfile. SaveAs (Server.MapPath (".. \\AtthFiles\\Meeting\\Meeting_"+ IDD. ToString () +fileextension)); Size= Pstfile. ContentLength/1024x768; Objdocument.insertdoc (5, IDD, Explain,"","", DateTime.Now.ToString ("YYYY-MM-DD"), Convert.ToInt32 (Hempid.value), filepath, size, hidwork. Value, Hidpro.                        Value);        }}}} sqltra.commit (); }Catch(Exception ex) {Sqltra.        Rollback (); }

ASP. NET-ROLLBACK TRANSACTION

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.