PublicList<userbaseinfomodel>Getcitybyexamid (Guid examid) {varCur_user = This. Getcurrentuser (); using(SqlConnection conn =NewSqlConnection (connectionString)) {Conn. Open (); SqlCommand cmd; using(SqlTransaction trans =Conn. BeginTransaction ()) {Try { stringsql =@"SELECT u.city from Exam_user_power p,dbo. User_baseinfo u WHERE [email protected] and P.userid=u.userid GROUP by U.city"; CMD=NewSqlCommand (SQL, Conn, trans); Cmd. Parameters.addwithvalue ("Examid", Examid); SqlDataAdapter SDA=NewSqlDataAdapter (CMD); DataSet DS=NewDataSet (); Sda. Fill (DS); List<UserBaseInfoModel> list = (list<userbaseinfomodel>) Ilistdataset.datasettoilist<userbaseinfomodel > (DS,0); Trans.commit (); returnlist; } Catch{trans. Rollback (); Throw; } finally{Conn. Close (); } } } return NULL; }
Transaction stitching SQL statement operations on the database. Exception rollback