2
Answers

Deleting record

Hi!
 
Please could you have a look on my code. Its doesnt delete record. But still saying "Deleted". What happen?
 
private void btnDelete_Click(object sender, EventArgs e)
{
conn = new SqlConnection(connstr);
comm = new SqlCommand();
conn.Open();
SqlParameter code = new SqlParameter("@cod", SqlDbType.NChar);
SqlParameter product = new SqlParameter("@prod", SqlDbType.VarChar);
SqlParameter price = new SqlParameter("@price", SqlDbType.NChar);
comm.Parameters.Add(code);
comm.Parameters.Add(product);
comm.Parameters.Add(price);
code.Value = txtcode.Text;
product.Value = txtproduct.Text;
price.Value = txtprice.Text;
comm.Connection = conn;
comm.CommandText = @"DELETE FROM company WHERE code='@cod'";
try
{
comm.ExecuteNonQuery();
MessageBox.Show("Deleted!");
}
catch (Exception)
{
MessageBox.Show("Not deleted");
}
finally
{
conn.Close();
}
}
}
}
 
Answers (2)