发布网友 发布时间:2022-04-08 21:03
共3个回答
懂视网 时间:2022-04-09 01:25
List<UserBaseInfoModel> GetCityByExamId(Guid ExamID) { var cur_user = this.GetCurrentUser(); using (SqlConnection conn = new SqlConnection(connectionString)) { conn.Open(); SqlCommand cmd; using (SqlTransaction trans = conn.BeginTransaction()) { try { string sql = @" SELECT u.City FROM Exam_User_Power p,dbo.User_BaseInfo u WHERE p.ExamID=@ExamID AND p.UserID=u.UserID GROUP BY u.City "; cmd = new SqlCommand(sql, conn, trans); cmd.Parameters.AddWithValue("ExamID", ExamID); SqlDataAdapter sda = new SqlDataAdapter(cmd); DataSet ds = new DataSet(); sda.Fill(ds); List<UserBaseInfoModel> list = (List<UserBaseInfoModel>)IListDataSet.DataSetToIList<UserBaseInfoModel>(ds, 0); trans.Commit(); return list; } catch { trans.Rollback(); throw; } finally { conn.Close(); } } } return null; }事务处理拼接sql语句对数据库的操作.异常回滚
标签:
热心网友 时间:2022-04-08 22:33
会的。热心网友 时间:2022-04-08 23:51
看你的语句怎么控制。一般的应用是有错误后不执行后面的代码。