I want to explain the mistake to user by using exception.
An error occurs because the column we want to delete during the deletion cannot be empty.
private void button2_Click(object sender, EventArgs e)
{
if (MessageBox.Show("Delete this Row !!!",
"YES",
MessageBoxButtons.YesNo,
MessageBoxIcon.Question) == DialogResult.Yes)
{
if (dataGridView1.CurrentRow != null)
{
int id = (int)dataGridView1.CurrentRow.Cells["WAREHOUSE_ID"].Value;
Alfa.Entities.Models.WAREHOUSE w = managerWAREHOUSE
.Find(x => x.WAREHOUSE_ID == id);
int sonuc = managerWAREHOUSE.Delete(w);
if (sonuc > 0)
{
MessageBox.Show("Record deleted");
Listele();
}
else
{
MessageBox.Show("Unable to delete record");
}
}
}
}
Actually it has to enter to the else statement. But before if statement it gives error.
Aucun commentaire:
Enregistrer un commentaire