private void button2_Click(object sender, EventArgs e) { int pID = Convert.ToInt32(comboBox2.SelectedValue); string Error = ""; DBProduct Obj = new DBProduct(); double PCount = Obj.geProductQuantityCount(pID, ref Error); double qun = Convert.ToInt64(textBox2.Text); if (qun < PCount) { con.Open(); string query = "INSERT INTO SalesInfo (CategoryName,PtName,SQuantity,Price,Date) VALUES ('" + comboBox1.Text + "','" + comboBox2.Text + "','" + textBox2.Text + "','" + comboBox3.Text + "', '" + dateTimePicker1.Value.Date + "')"; SqlDataAdapter sda = new SqlDataAdapter(query, con); sda.SelectCommand.ExecuteNonQuery(); con.Close(); MessageBox.Show("Sell Submitted !"); } else { MessageBox.Show("Quantity exceeded the available limit in stock !!"); MessageBox.Show("Available Quantity of the selected product : " + Convert.ToString(PCount)); } textBox2.Clear(); textBox3.Clear(); }