Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. .NET (Core and Framework)
  4. stop the flow the project

stop the flow the project

Scheduled Pinned Locked Moved .NET (Core and Framework)
questionhelp
14 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    kulandaivel_mca2007
    wrote on last edited by
    #1

    is it possible to stop the flow of the project? i get error and it is catched in try catch block... after that i don't want to continue... i want transfer the flow to my starting page... how can i do this...

    W 1 Reply Last reply
    0
    • K kulandaivel_mca2007

      is it possible to stop the flow of the project? i get error and it is catched in try catch block... after that i don't want to continue... i want transfer the flow to my starting page... how can i do this...

      W Offline
      W Offline
      Wendelius
      wrote on last edited by
      #2

      If it's a method you add for example return the the end of the catch block if there are statements outside the try-chatch structure. However, finally portion will still be executed. Then on the calling side you must handle this situation so that you don't continue there and so on.

      The need to optimize rises from a bad design.My articles[^]

      K 1 Reply Last reply
      0
      • W Wendelius

        If it's a method you add for example return the the end of the catch block if there are statements outside the try-chatch structure. However, finally portion will still be executed. Then on the calling side you must handle this situation so that you don't continue there and so on.

        The need to optimize rises from a bad design.My articles[^]

        K Offline
        K Offline
        kulandaivel_mca2007
        wrote on last edited by
        #3

        actually it is a connection coding... (i got error in this) i catch this but... control transfered to original form... connection coding functuion written in class file.. this connection coding function is called in remaining forms...

        W 1 Reply Last reply
        0
        • K kulandaivel_mca2007

          actually it is a connection coding... (i got error in this) i catch this but... control transfered to original form... connection coding functuion written in class file.. this connection coding function is called in remaining forms...

          W Offline
          W Offline
          Wendelius
          wrote on last edited by
          #4

          Can you post the code? It doesn't matter what you do in the code, but it's important that you model the flow so that methods exit nicely and the calling method understands not to continue with execution. But as said, it's a bit hard to say more without the code.

          The need to optimize rises from a bad design.My articles[^]

          K 1 Reply Last reply
          0
          • W Wendelius

            Can you post the code? It doesn't matter what you do in the code, but it's important that you model the flow so that methods exit nicely and the calling method understands not to continue with execution. But as said, it's a bit hard to say more without the code.

            The need to optimize rises from a bad design.My articles[^]

            K Offline
            K Offline
            kulandaivel_mca2007
            wrote on last edited by
            #5

            // written in class file public void mthOpenConnection() { try { string[] datasource = File.ReadAllLines("d:\\k2.txt"); if (datasource[0] != "") { objprop.connection = "Data Source=" + datasource[0] + ";Initial Catalog=Inventory_VS;User ID=sa;Password=sa"; objCon = new SqlConnection(objprop.connection); if (objCon.State != ConnectionState.Open) { objCon.Open(); } } } catch { MessageBox.Show("ENTER CORRECT DATA SOURCE NAME IN UR TEXT FILE"); } } // this is my login form here i call my open connection public DataSet mthGetLogin(Properties objproperties) { objDBconnection.mthOpenConnection(); SqlDataAdapter objDALogin = new SqlDataAdapter("sp_login", objDBconnection.objCon); objDALogin.SelectCommand.Parameters.Add(new SqlParameter("@uname", objproperties.Username)); objDALogin.SelectCommand.Parameters.Add(new SqlParameter("@pword", objproperties.Password)); objDALogin.SelectCommand.CommandType = CommandType.StoredProcedure; objDALogin.Fill(objDSLogin); return objDSLogin; }

            W 1 Reply Last reply
            0
            • K kulandaivel_mca2007

              // written in class file public void mthOpenConnection() { try { string[] datasource = File.ReadAllLines("d:\\k2.txt"); if (datasource[0] != "") { objprop.connection = "Data Source=" + datasource[0] + ";Initial Catalog=Inventory_VS;User ID=sa;Password=sa"; objCon = new SqlConnection(objprop.connection); if (objCon.State != ConnectionState.Open) { objCon.Open(); } } } catch { MessageBox.Show("ENTER CORRECT DATA SOURCE NAME IN UR TEXT FILE"); } } // this is my login form here i call my open connection public DataSet mthGetLogin(Properties objproperties) { objDBconnection.mthOpenConnection(); SqlDataAdapter objDALogin = new SqlDataAdapter("sp_login", objDBconnection.objCon); objDALogin.SelectCommand.Parameters.Add(new SqlParameter("@uname", objproperties.Username)); objDALogin.SelectCommand.Parameters.Add(new SqlParameter("@pword", objproperties.Password)); objDALogin.SelectCommand.CommandType = CommandType.StoredProcedure; objDALogin.Fill(objDSLogin); return objDSLogin; }

              W Offline
              W Offline
              Wendelius
              wrote on last edited by
              #6

              Okay, you could use for example bools:

              public bool mthOpenConnection()
              {
              try
              {
              string[] datasource = File.ReadAllLines("d:\\k2.txt");
              if (datasource[0] != "")
              {
              objprop.connection = "Data Source=" + datasource[0] + ";Initial Catalog=Inventory_VS;User ID=sa;Password=sa";
              objCon = new SqlConnection(objprop.connection);
              if (objCon.State != ConnectionState.Open)
              {
              objCon.Open();
              }
              }
              }
              catch
              {
              MessageBox.Show("ENTER CORRECT DATA SOURCE NAME IN UR TEXT FILE");
              return false;
              }
              return true;
              }

              and then

              public DataSet mthGetLogin(Properties objproperties)
              {
              if (!objDBconnection.mthOpenConnection())
              {
              return null;
              }
              SqlDataAdapter objDALogin = new SqlDataAdapter("sp_login", objDBconnection.objCon);
              objDALogin.SelectCommand.Parameters.Add(new SqlParameter("@uname", objproperties.Username));
              objDALogin.SelectCommand.Parameters.Add(new SqlParameter("@pword", objproperties.Password));
              objDALogin.SelectCommand.CommandType = CommandType.StoredProcedure;
              objDALogin.Fill(objDSLogin);
              return objDSLogin;
              }

              The need to optimize rises from a bad design.My articles[^]

              K 2 Replies Last reply
              0
              • W Wendelius

                Okay, you could use for example bools:

                public bool mthOpenConnection()
                {
                try
                {
                string[] datasource = File.ReadAllLines("d:\\k2.txt");
                if (datasource[0] != "")
                {
                objprop.connection = "Data Source=" + datasource[0] + ";Initial Catalog=Inventory_VS;User ID=sa;Password=sa";
                objCon = new SqlConnection(objprop.connection);
                if (objCon.State != ConnectionState.Open)
                {
                objCon.Open();
                }
                }
                }
                catch
                {
                MessageBox.Show("ENTER CORRECT DATA SOURCE NAME IN UR TEXT FILE");
                return false;
                }
                return true;
                }

                and then

                public DataSet mthGetLogin(Properties objproperties)
                {
                if (!objDBconnection.mthOpenConnection())
                {
                return null;
                }
                SqlDataAdapter objDALogin = new SqlDataAdapter("sp_login", objDBconnection.objCon);
                objDALogin.SelectCommand.Parameters.Add(new SqlParameter("@uname", objproperties.Username));
                objDALogin.SelectCommand.Parameters.Add(new SqlParameter("@pword", objproperties.Password));
                objDALogin.SelectCommand.CommandType = CommandType.StoredProcedure;
                objDALogin.Fill(objDSLogin);
                return objDSLogin;
                }

                The need to optimize rises from a bad design.My articles[^]

                K Offline
                K Offline
                kulandaivel_mca2007
                wrote on last edited by
                #7

                it works fine... but the flow didn't stoped bcz next consequetive lines needs valid open connection... (but i catch invalid connection in my try block)(contradictory) it ends in error...

                W 1 Reply Last reply
                0
                • W Wendelius

                  Okay, you could use for example bools:

                  public bool mthOpenConnection()
                  {
                  try
                  {
                  string[] datasource = File.ReadAllLines("d:\\k2.txt");
                  if (datasource[0] != "")
                  {
                  objprop.connection = "Data Source=" + datasource[0] + ";Initial Catalog=Inventory_VS;User ID=sa;Password=sa";
                  objCon = new SqlConnection(objprop.connection);
                  if (objCon.State != ConnectionState.Open)
                  {
                  objCon.Open();
                  }
                  }
                  }
                  catch
                  {
                  MessageBox.Show("ENTER CORRECT DATA SOURCE NAME IN UR TEXT FILE");
                  return false;
                  }
                  return true;
                  }

                  and then

                  public DataSet mthGetLogin(Properties objproperties)
                  {
                  if (!objDBconnection.mthOpenConnection())
                  {
                  return null;
                  }
                  SqlDataAdapter objDALogin = new SqlDataAdapter("sp_login", objDBconnection.objCon);
                  objDALogin.SelectCommand.Parameters.Add(new SqlParameter("@uname", objproperties.Username));
                  objDALogin.SelectCommand.Parameters.Add(new SqlParameter("@pword", objproperties.Password));
                  objDALogin.SelectCommand.CommandType = CommandType.StoredProcedure;
                  objDALogin.Fill(objDSLogin);
                  return objDSLogin;
                  }

                  The need to optimize rises from a bad design.My articles[^]

                  K Offline
                  K Offline
                  kulandaivel_mca2007
                  wrote on last edited by
                  #8

                  is anyother way available.... like goto,break,Abandon...

                  W 1 Reply Last reply
                  0
                  • K kulandaivel_mca2007

                    it works fine... but the flow didn't stoped bcz next consequetive lines needs valid open connection... (but i catch invalid connection in my try block)(contradictory) it ends in error...

                    W Offline
                    W Offline
                    Wendelius
                    wrote on last edited by
                    #9

                    If you added the modification to mthGetLogin that I wrote, the execution in that method won't continue because I added return null to it. However, this is only part of your code so you must use this idea in all places where you want to 'break' the execution

                    The need to optimize rises from a bad design.My articles[^]

                    K 1 Reply Last reply
                    0
                    • K kulandaivel_mca2007

                      is anyother way available.... like goto,break,Abandon...

                      W Offline
                      W Offline
                      Wendelius
                      wrote on last edited by
                      #10

                      goto can go only to a specific point inside a method. break exits a loop so there's no quick way to do this. One way is to throw an exception inside a catch. Then catch this exception at the level you want.

                      The need to optimize rises from a bad design.My articles[^]

                      K 2 Replies Last reply
                      0
                      • W Wendelius

                        If you added the modification to mthGetLogin that I wrote, the execution in that method won't continue because I added return null to it. However, this is only part of your code so you must use this idea in all places where you want to 'break' the execution

                        The need to optimize rises from a bad design.My articles[^]

                        K Offline
                        K Offline
                        kulandaivel_mca2007
                        wrote on last edited by
                        #11

                        s u r right... see this peace of code... this is my loging forms's button(submit) click event... when the program try to read table values error occurs... private void button2_Click_1(object sender, EventArgs e) { objproperties.Username = txtuname.Text; objproperties.Password = txtpword.Text; objDSLogin = objfunction.mthGetLogin(objproperties); if (objDSLogin.Tables[0].Rows.Count > 0) { if (objDSLogin.Tables[0].Rows[0]["status"].ToString() == "User") { objproperties.Username = txtuname.Text; objfunction.mthUsernameInsert(objproperties); this.Hide(); UserForm uf = new UserForm(); uf.Show(); } else if (objDSLogin.Tables[0].Rows[0]["status"].ToString() == "Admin") { this.Hide(); AdminForm1 af = new AdminForm1(); af.Show(); } else { label4.Text = "Login Failed... Try Again"; label4.Visible = true; txtpword.Text = ""; txtuname.Focus(); } } else { label4.Visible = true; txtpword.Text = ""; txtuname.Focus(); } }

                        W 1 Reply Last reply
                        0
                        • W Wendelius

                          goto can go only to a specific point inside a method. break exits a loop so there's no quick way to do this. One way is to throw an exception inside a catch. Then catch this exception at the level you want.

                          The need to optimize rises from a bad design.My articles[^]

                          K Offline
                          K Offline
                          kulandaivel_mca2007
                          wrote on last edited by
                          #12

                          how i can do this... guide me..

                          1 Reply Last reply
                          0
                          • K kulandaivel_mca2007

                            s u r right... see this peace of code... this is my loging forms's button(submit) click event... when the program try to read table values error occurs... private void button2_Click_1(object sender, EventArgs e) { objproperties.Username = txtuname.Text; objproperties.Password = txtpword.Text; objDSLogin = objfunction.mthGetLogin(objproperties); if (objDSLogin.Tables[0].Rows.Count > 0) { if (objDSLogin.Tables[0].Rows[0]["status"].ToString() == "User") { objproperties.Username = txtuname.Text; objfunction.mthUsernameInsert(objproperties); this.Hide(); UserForm uf = new UserForm(); uf.Show(); } else if (objDSLogin.Tables[0].Rows[0]["status"].ToString() == "Admin") { this.Hide(); AdminForm1 af = new AdminForm1(); af.Show(); } else { label4.Text = "Login Failed... Try Again"; label4.Visible = true; txtpword.Text = ""; txtuname.Focus(); } } else { label4.Visible = true; txtpword.Text = ""; txtuname.Focus(); } }

                            W Offline
                            W Offline
                            Wendelius
                            wrote on last edited by
                            #13

                            So based on the previous example I wrote, you could:

                            ...
                            objproperties.Password = txtpword.Text;
                            objDSLogin = objfunction.mthGetLogin(objproperties);
                            if (objDSLogin == null)
                            {
                            return;
                            }
                            if (objDSLogin.Tables[0].Rows.Count > 0)
                            {
                            ...

                            The need to optimize rises from a bad design.My articles[^]

                            1 Reply Last reply
                            0
                            • W Wendelius

                              goto can go only to a specific point inside a method. break exits a loop so there's no quick way to do this. One way is to throw an exception inside a catch. Then catch this exception at the level you want.

                              The need to optimize rises from a bad design.My articles[^]

                              K Offline
                              K Offline
                              kulandaivel_mca2007
                              wrote on last edited by
                              #14

                              public bool mthOpenConnection() { try { objprop.J = 0; string[] datasource = File.ReadAllLines("d:\\k2.txt"); if (datasource[0] != "") { objprop.connection = "Data Source=" + datasource[0] + ";Initial Catalog=Inventory_VS;User ID=sa;Password=sa"; objCon = new SqlConnection(objprop.connection); if (objCon.State != ConnectionState.Open) { objCon.Open(); } } } catch (Exception ex) { MessageBox.Show("ENTER CORRECT DATA SOURCE NAME IN UR TEXT FILE"); return false; } return true; } how i can throw my exceptions....

                              1 Reply Last reply
                              0
                              Reply
                              • Reply as topic
                              Log in to reply
                              • Oldest to Newest
                              • Newest to Oldest
                              • Most Votes


                              • Login

                              • Don't have an account? Register

                              • Login or register to search.
                              • First post
                                Last post
                              0
                              • Categories
                              • Recent
                              • Tags
                              • Popular
                              • World
                              • Users
                              • Groups