//充点
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();
}
}
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();
}
}
本文介绍了一个使用C#和SQL Server实现的积分更新方法,通过事务处理确保数据的一致性和安全性。该方法首先从指定表中读取当前积分,然后更新积分值,并记录操作的IP地址及时间。
511

被折叠的 条评论
为什么被折叠?



