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

浙公网安备 33010602011771号