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

Your request is not so clear, but i think you want to branch or delimit code execution after this function call. If that's what you need, you can conditionally execute the code after the connTest is called, or provide more details about what you really want to do.

what you want to ask? You elaborated confusion. Any way it is obvious that when you call a function it will return the pointer to caller after completion if not then where you suppose it have to go? Mean what code you want to execute after end of this function? you can call the other function after calling this one.... but if you write nothing after calling this function you just leave it i don't think it creates any problem it will automatically pass pointer to next possible function according to your programming.... you have to check conditions there is no way to avoid lines of code while coding

Edited 5 Years Ago by abelLazm: n/a

I apologoise for the confusion.
I do believe that dxider has got the correct end of the stick.
I understand that I can use a condition to execute the code after connTest I was just hoping there was some 1 line of code that would do the same thing. Going off your responses I see that there is not an easier solution.

Thank you for your responses

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 think

this.dispose()

can solve your problem .

If you cant be clear in your question, how do you expect to have a correct answer. Try to provide more details when posting questions.

Edited 5 Years Ago by dxider: n/a

This question has already been answered. Start a new discussion instead.