After i enter quantity greater than inventory in database, i should get the error and this works fine. but my problem is that even after changing the quantity to lower than inventory, the error still pops up and cannot allow insert to proceed.
SqlConnection Connection = new SqlConnection("Data Source=localhost;Initial Catalog=warehousedb;Integrated Security=True ");
SqlDataAdapter INVadapter = new SqlDataAdapter("Select ItemID, ItemName, Quantity FROM inventory ", Connection);
int SelectedDPItem;
int InventoryQTY;
int DinventoryQTY;
//SelectedDPItem = Convert.ToInt32(DropDownListItem_D.SelectedValue);
SelectedDPItem = int.Parse(DropDownListItem_D.SelectedValue.ToString());
// Open Connection
Connection.Open();
SqlCommand Inventorychkcommand = new SqlCommand(("Select Quantity FROM inventory " + ("WHERE (ItemName LIKE \'"
+ (DropDownListItem_D.Text + "\')"))), Connection);
InventoryQTY = Convert.ToInt32(Inventorychkcommand.ExecuteScalar());
DinventoryQTY = Convert.ToInt32(txtQuantity_D.Text);
Connection.Close();
if (InventoryQTY == 0 || InventoryQTY < DinventoryQTY)
ClientScript.RegisterStartupScript(this.GetType(), "key", "<script>alert('sorry , Stock Balance is less than requested quantity. Item cannot be dispatched')</script>");
else
// procedure of inserting the record
AddNewRecordRowToGrid();