i am trying to compare the value of textbox with the data in database, and if the value in textbox is bigger den the value of data in database, a alert message will appear and if it is smaller than the value of the data in the datebase, it will minus the database value with the value of textbox and update the value of database. there is no error but when i click on the button, nothing appear and no changes have made to the database. is there anything wrong with my code? thx
protected void btn_buy_Click(object sender, EventArgs e)
{
hookUp = new SqlConnection("Server=localhost\\SqlExpress;Database=VoteNow;" +
"Integrated Security=True" );
sqlCmd = new SqlCommand("SELECT UnitAvailable FROM stockdetails1 WHERE StockID = 3", hookUp);
hookUp.Open();
reader = sqlCmd.ExecuteReader();
int amountkey;
amountkey = Convert.ToInt32(amount.Text);
while (reader.Read())
{
int unitavailable = reader.GetInt32(0);
int unitavailable1;
if (amountkey <= unitavailable)
{
unitavailable1 = unitavailable - amountkey;
SqlCommand sqlupdateCmd = new SqlCommand("UPDATE StockDetails Set UnitAvailable = '+unitavailable1+' WHERE StockID = 3", hookUp);
sqlupdateCmd.ExecuteNonQuery();
Response.Write("<script LANGUAGE='JavaScript'> alert('The units available is enough.')</script>");
}
else
{
Response.Write("<script LANGUAGE='JavaScript'> alert('The units available is not enough.')</script>");
}
}
reader.Close();
hookUp.Close();
}
}