4
Answers

update query executed but record not updated

Atul Rokade

Atul Rokade

7y
219
1
Hi all,
 
   
Iam doing one task where i want to executed update query i have table name is Medicine_Available_Detail here iam storing total medicine available column name is Availability,I have one datagridview where im putting Quantity of that Medicine after user enter Quantity of particular medicine then it table update as Availability-Quantity for that medicine i written a code but its executed but record not updated
 
private void dataGridView1_RowLeave(object sender, DataGridViewCellEventArgs e)
{
int quantity = Convert.ToInt16(dataGridView1.Rows[e.RowIndex].Cells["Quantity"].Value);
 
cmd = new OleDbCommand("update Medicine_Available_Detail set [Availability]=[Availability]-@Quantity where [Medicine_Name]=@Medicine_Name", con);
cmd.Parameters.AddWithValue("@Quantity", quantity);
cmd.Parameters.AddWithValue("@Medicine_Name", medicinename);
 
con.Open();
int n = cmd.ExecuteNonQuery();
con.Close();
 
Answers (4)