SQL server 的数据库处理帮助类(501)

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;
  }
 }

}

  

原文地址:https://www.cnblogs.com/aDoc/p/12814086.html