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