我可以这样做吗?数据库更新期间可以增加一些值吗?
int somevalue=500;
string getUpSql = "UPDATE money FROM bank SET Money= @Money + somevalue WHERE [email protected]";
我想加一些钱给点击按钮的账户
protected void BtnWork_Click(object sender, EventArgs e)
{
MembershipUser currentUser = Membership.GetUser();
Guid currentUserId = (Guid)currentUser.ProviderUserKey;
string ConnectionString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
string getUpSql = "UPDATE money FROM bank SET Money= @Money + somevalue WHERE [email protected]";
using (SqlConnection myConnection = new SqlConnection(ConnectionString))
{
SqlCommand myCommand = new SqlCommand(getUpSql, myConnection);
myConnection.Open();
myCommand.Parameters.AddWithValue("@Money",SqlDbType.Int);
myCommand.ExecuteNonQuery();
myConnection.Close();
}
如果你使用'@ UserId',使确定将其作为参数传入。发布错误消息和Custon_MoneyWork表的定义会有所帮助。 – Andomar
有没有错误,它只是不工作:) @用户ID是好的。 – RaShe
问题是 - 我怎么加“somevalue”? – RaShe