2016-07-06 90 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()); 
}