Hello,
Before I begin, I have had a quick look around for a solution to this problem however time is not something I have lots of right this moment so I am going to post this and hope that by the time I return to complete my work there is an answer :D
I curruently have a form that connects via several functions, to a database. In order to remove possible errors I have decided to check that the database connection exists at the start of each function, to do this I made a seperate function as can be seen below:
private void connTest()
{
cnn.ConnectionString = "Data Source=ASERVER;Initial Catalog=DB;Integrated Security=True";
try
{
cmd = cnn.CreateCommand();
cmd.CommandText = "SELECT * FROM priority";
cmd.Connection.Open();
cmd.ExecuteNonQuery();
cmd.Connection.Close();
}
catch
{
MessageBox.Show("An error occured when the application tried to access the database.\nIs the database online?\nError code: 3", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
this.Close();
fcaller.Show(); //this will just cause the parent form to re-appear
}
}
Once the code gets to 'this.Close();' it goes through the connTest function again, don't know why but this isn't what I am concerned about at the moment, but if anyone can think why then please do let me know :)
My problem is that after this function has finished it then goes back to the function where connTest was called from and continues to finish that function, that is something I do not want.
I want to know if there is any command that will end everything to do with this particular form within the connTest function, like this.destroy() or something? ;)
I could get the same effect by getting connTest to return a boolean and then get the caller function to check that boolean value, but that would require adding a lot more code than I want to, however, if there is no quick way then this method will have to do.
Thank you very much for taking the time to read this and thank you in advance for any responses