2016-07-06 109 views
-8
protected void btn_redeem_Click(object sender, EventArgs e) 
{ 
    int lol = int.Parse(lbl_TotalPrice.Text,System.Globalization.NumberStyles.Currency); 
    double nprice = lol * 0.05; 
    int newpoints=0 ; 
    if (int.Parse(Session["points"].ToString()) >= 1000) 
    { 
     double redeem = lol - nprice; 
     lbl_TotalPrice.Text = redeem.ToString("C"); 
     newpoints = int.Parse(Session["points"].ToString()) - 1000; 
    } 
    SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["HealthDBContext"].ConnectionString); 
    conn.Open(); 
    string queryStr = "UPDATE Users SET Points ='" + newpoints + "'WHERE UserName=" + Session["New"].ToString(); 
    SqlCommand com = new SqlCommand(queryStr, conn); 

    conn.Close(); 
} 
+2

你可以至少給的什麼是不工作的一些跡象。發生什麼錯誤/異常?代碼中的哪個位置? –

+2

沒有例外消息?我們無法讀懂你的想法... – 2016-07-06 08:10:13

+0

它沒有更新用戶的要點 –

回答

0

添加.ExecuteNonQuery執行查詢,並添加的try-catch塊捕捉任何異常:

try 
{ 
    ... 
    SqlCommand com = new SqlCommand(queryStr, conn); 
    com.ExecuteNonQuery(); 
    conn.Close(); 
    ... 
} 
catch (Exception ex) 
{ 
    MessageBox.Show(ex.ToString()); 
}