我可以這樣做嗎?數據庫更新期間可以增加一些值嗎?
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