Look at the documentation for
DialogResult[
^].
The DialogResult object is a windows form, which means that it needs to be disposed. The best way to implement this is:
using(DialogResult choice = MessageBox.Show("Are you sure want to delete this Question?\nDeleted question can not be reovered.", "Delet Question", MessageBoxButtons.YesNo))
{
if (choice == DialogResult.Yes)
{
dataGridView.Rows.RemoveAt(qno - 1);
queryDelete = "delete from " + subject + " where QueNo="
+ qno + "and SetNo=" + setNo;
try
{
connection.Open();
command = new OleDbCommand(queryDelete, connection);
command.ExecuteNonQuery();
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
connection.Close();
MessageBox.Show("Question Deleted.", "Deleted");
}
else
{
}
}