您的位置:首页 > 移动开发

Data Access Application Block 中事务的使用

2008-04-08 11:44 726 查看
//充点
public static int ChargePoint(decimal id, String table, decimal point, String ip)
{
decimal oldPoint = 0;
SqlConnection con = new SqlConnection(BasePage.GetConnectString());
String strSQL = null;
con.Open();
SqlTransaction tran = con.BeginTransaction();
try
{
strSQL = String.Format("select points from {0} where {0}ID={1}", table, id);
//Debug.Log(strSQL);
oldPoint = (Decimal)SqlHelper.ExecuteScalar(tran, CommandType.Text, strSQL);

strSQL = String.Format("update {0} set points={1},ip='{2}',time=GETDATE() where {0}ID={3}", table, oldPoint + point, ip, id);
SqlHelper.ExecuteNonQuery(tran, CommandType.Text, strSQL);
tran.Commit();
return 1;
}
catch (Exception ex)
{
tran.Rollback();

return 0;
}
finally
{
con.Close();
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: