public static T Excute<T>(string sql, Func<SqlCommand, T> func) { using (SqlConnection conn = new SqlConnection("")) { SqlTransaction trans = conn.BeginTransaction(); try { SqlCommand command = new SqlCommand(sql, conn); T t = func(command); trans.Commit(); return t; } catch (Exception ex) { Console.WriteLine(ex.Message); trans.Rollback(); throw ex; } } }