I have 2 forms. I get the requested data to connect to database in Form1, send it to Form2, show Form2 and fill the datagridview in constructor of Form2 after connecting to database. Here I check if there is any rows in sdr (SqlDataReader). If not, what I want to do is stopping the Form2 to be loaded and turn back to Form1.
I tried this.close() but it doesn’t work while executing the constructor of Form2.
if (!sdr.HasRows)
{
MessageBox.Show("No Data!", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
this.Close();
}
Any ideas ?
The closing and in general loading of the data has not to be done inside
ctorof theForm, but inside Form.Load event.For example: