I am writing to develop a program concerning stock of a firm.
I have variable quantity in stock in int, ı am trying to get all quantity and compare with the result written on textbox.
I am using the following code:
SqlConnection sqlcon = new SqlConnection("server=.;database=DB_TEST;trusted_connection=true"); - SERVER CONNECTION
SqlCommand sqlcmd = new SqlCommand("Select SUM(Quantity) from Stock where ProductID='" + cmbxProductID.SelectedValue + "'", sqlcon); - GETTING TOTAL QUANTITY FROM DATABASE - quantity in int
sqlcon.Open(); - SQL CONNECTION OPEN
textBox1.Text = sqlcmd.ExecuteScalar().ToString(); -- transfering total quantity to textbox1
int result=int.Parse(textBox1.Text); -- CONVERT CONTENT OF TEXTBOX to ınt
if (result == 0)
{
MessageBox.Show("Stock is not adequate");
}
sqlcmd.ExecuteNonQuery();
sqlcon.Close()
MessageBox.Show("Stock is OK");