Link to home
Start Free TrialLog in
Avatar of Tom Knowlton
Tom KnowltonFlag for United States of America

asked on

Unreachable code

I do not understand why this portion of my code is considered "unreachable" by the compiler:


                  switch(type)
                                    {
                                          case("SelfEmployed"):return SelfEmployed;
                                                break;
                                          case("ActiveMilitary"):return ActiveMilitary;
                                                break;
                                          case("WorkForRelative"):return WorkForRelative;
                                                break;
                                          default:
                                                return 1;
                                                break;
                                    }
                  




Here is the function:



public int MPPQuestionsStatus(long tempEntryID, string TempConnectionString, string type)
                  {
                        string strTempSQL = "";

                        int SelfEmployed=0;
                        int ActiveMilitary=0;
                        int WorkForRelative=0;

                        string SelfEmployedRaw="";
                        string ActiveMilitaryRaw="";
                        string WorkForRelativeRaw="";



      
                        strTempSQL = "ShowMPPAnswers " + tempEntryID.ToString();
               
                        //Create DataSet
                        SqlConnection TempConnection = new SqlConnection(TempConnectionString);
                        SqlDataAdapter TempDataAdapter = new SqlDataAdapter(strTempSQL,TempConnection);
                        DataSet TempDataSet = new DataSet();
                        TempDataAdapter.Fill(TempDataSet, "Temp");
                        DataTable TempDataTable = TempDataSet.Tables["Temp"];
                        SqlCommandBuilder TempCmdBuilder = new SqlCommandBuilder(TempDataAdapter);                  

                        foreach (DataRow myDataRow in TempDataSet.Tables["Temp"].Rows)
                        {
                              try
                              {
                                    
                                    SelfEmployedRaw = myDataRow.IsNull("self-employed") ? "No" : myDataRow["self-employed"].ToString();
                                    ActiveMilitaryRaw = myDataRow.IsNull("Active Military") ? "No" : myDataRow["Active Military"].ToString();
                                    WorkForRelativeRaw = myDataRow.IsNull("work for relative") ? "No" : myDataRow["work for relative"].ToString();

                                    switch(SelfEmployedRaw)
                                    {
                                          case("No"):SelfEmployed = 0;
                                                break;
                                          case("Yes"):SelfEmployed = 1;
                                                break;
                                          default:
                                                SelfEmployed = 1;
                                                break;
                                    }

                                    switch(ActiveMilitaryRaw)
                                    {
                                          case("No"):ActiveMilitary = 0;
                                                break;
                                          case("Yes"):ActiveMilitary = 1;
                                                break;
                                          default:
                                                ActiveMilitary = 1;
                                                break;
                                    }


                                    switch(WorkForRelativeRaw)
                                    {
                                          case("No"):WorkForRelative = 0;
                                                break;
                                          case("Yes"):WorkForRelative = 1;
                                                break;
                                          default:
                                                WorkForRelative = 1;
                                                break;
                                    }

                                    switch(type)
                                    {
                                          case("SelfEmployed"):return SelfEmployed;
                                                break;
                                          case("ActiveMilitary"):return ActiveMilitary;
                                                break;
                                          case("WorkForRelative"):return WorkForRelative;
                                                break;
                                          default:
                                                return 1;
                                                break;
                                    }
                              }
                              catch(Exception e)
                              {
                                    System.Diagnostics.Debug.WriteLine(e.Message + ":::::::" + e.StackTrace);
                              }
                        }                        
                  }
Avatar of Tom Knowlton
Tom Knowlton
Flag of United States of America image

ASKER

Here was my solution:



                  public int MPPQuestionsStatus(long tempEntryID, string TempConnectionString, string type)
                  {
                        string strTempSQL = "";

                        int SelfEmployed=0;
                        int ActiveMilitary=0;
                        int WorkForRelative=0;

                        string SelfEmployedRaw="";
                        string ActiveMilitaryRaw="";
                        string WorkForRelativeRaw="";

                        int FinalAnswer=1;



      
                        strTempSQL = "ShowMPPAnswers " + tempEntryID.ToString();
               
                        //Create DataSet
                        SqlConnection TempConnection = new SqlConnection(TempConnectionString);
                        SqlDataAdapter TempDataAdapter = new SqlDataAdapter(strTempSQL,TempConnection);
                        DataSet TempDataSet = new DataSet();
                        TempDataAdapter.Fill(TempDataSet, "Temp");
                        DataTable TempDataTable = TempDataSet.Tables["Temp"];
                        SqlCommandBuilder TempCmdBuilder = new SqlCommandBuilder(TempDataAdapter);                  

                        foreach (DataRow myDataRow in TempDataSet.Tables["Temp"].Rows)
                        {
                              try
                              {
                                    
                                    SelfEmployedRaw = myDataRow.IsNull("self-employed") ? "No" : myDataRow["self-employed"].ToString();
                                    ActiveMilitaryRaw = myDataRow.IsNull("Active Military") ? "No" : myDataRow["Active Military"].ToString();
                                    WorkForRelativeRaw = myDataRow.IsNull("work for relative") ? "No" : myDataRow["work for relative"].ToString();

                                    switch(SelfEmployedRaw)
                                    {
                                          case("No"):SelfEmployed = 0;
                                                break;
                                          case("Yes"):SelfEmployed = 1;
                                                break;
                                          default:
                                                SelfEmployed = 1;
                                                break;
                                    }

                                    switch(ActiveMilitaryRaw)
                                    {
                                          case("No"):ActiveMilitary = 0;
                                                break;
                                          case("Yes"):ActiveMilitary = 1;
                                                break;
                                          default:
                                                ActiveMilitary = 1;
                                                break;
                                    }


                                    switch(WorkForRelativeRaw)
                                    {
                                          case("No"):WorkForRelative = 0;
                                                break;
                                          case("Yes"):WorkForRelative = 1;
                                                break;
                                          default:
                                                WorkForRelative = 1;
                                                break;
                                    }

                                    switch(type)
                                    {
                                          case("SelfEmployed"):FinalAnswer = SelfEmployed;
                                                break;
                                          case("ActiveMilitary"):FinalAnswer = ActiveMilitary;
                                                break;
                                          case("WorkForRelative"):FinalAnswer =  WorkForRelative;
                                                break;
                                          default:
                                                FinalAnswer = 1;
                                                break;
                                    }//end switch                              

                              }//end try
                              catch(Exception e)
                              {
                                    System.Diagnostics.Debug.WriteLine(e.Message + ":::::::" + e.StackTrace);
                              }                              
                        }      
                  
                        return FinalAnswer;
                  }
ASKER CERTIFIED SOLUTION
Avatar of muzzy2003
muzzy2003

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Experts please read this:  I intend to ask this to be marked as

PAQ / Refund Points.
muzzy:

Would you like the points?

Does not matter to me either way.
Avatar of muzzy2003
muzzy2003

If you hadn't understood why your change fixed things and you now do, then feel free to give me some. Won't be in the least bit offended if you don't - I hadn't seen your last post when I posted mine.
Sorry - just realised my post was before yours anyway, so you knew that. Anyway, comments stand.
Enjoy!!!

Tom
OK, thanks very much.