Tom Knowlton
asked on
Unreachable code
I do not understand why this portion of my code is considered "unreachable" by the compiler:
switch(type)
{
case("SelfEmployed"):retur n SelfEmployed;
break;
case("ActiveMilitary"):ret urn ActiveMilitary;
break;
case("WorkForRelative"):re turn 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(TempConnecti onString);
SqlDataAdapter TempDataAdapter = new SqlDataAdapter(strTempSQL, TempConnec tion);
DataSet TempDataSet = new DataSet();
TempDataAdapter.Fill(TempD ataSet, "Temp");
DataTable TempDataTable = TempDataSet.Tables["Temp"] ;
SqlCommandBuilder TempCmdBuilder = new SqlCommandBuilder(TempData Adapter);
foreach (DataRow myDataRow in TempDataSet.Tables["Temp"] .Rows)
{
try
{
SelfEmployedRaw = myDataRow.IsNull("self-emp loyed") ? "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"):WorkForRelativ e = 1;
break;
default:
WorkForRelative = 1;
break;
}
switch(type)
{
case("SelfEmployed"):retur n SelfEmployed;
break;
case("ActiveMilitary"):ret urn ActiveMilitary;
break;
case("WorkForRelative"):re turn WorkForRelative;
break;
default:
return 1;
break;
}
}
catch(Exception e)
{
System.Diagnostics.Debug.W riteLine(e .Message + ":::::::" + e.StackTrace);
}
}
}
switch(type)
{
case("SelfEmployed"):retur
break;
case("ActiveMilitary"):ret
break;
case("WorkForRelative"):re
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(TempConnecti
SqlDataAdapter TempDataAdapter = new SqlDataAdapter(strTempSQL,
DataSet TempDataSet = new DataSet();
TempDataAdapter.Fill(TempD
DataTable TempDataTable = TempDataSet.Tables["Temp"]
SqlCommandBuilder TempCmdBuilder = new SqlCommandBuilder(TempData
foreach (DataRow myDataRow in TempDataSet.Tables["Temp"]
{
try
{
SelfEmployedRaw = myDataRow.IsNull("self-emp
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
break;
default:
ActiveMilitary = 1;
break;
}
switch(WorkForRelativeRaw)
{
case("No"):WorkForRelative
break;
case("Yes"):WorkForRelativ
break;
default:
WorkForRelative = 1;
break;
}
switch(type)
{
case("SelfEmployed"):retur
break;
case("ActiveMilitary"):ret
break;
case("WorkForRelative"):re
break;
default:
return 1;
break;
}
}
catch(Exception e)
{
System.Diagnostics.Debug.W
}
}
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Experts please read this: I intend to ask this to be marked as
PAQ / Refund Points.
PAQ / Refund Points.
ASKER
muzzy:
Would you like the points?
Does not matter to me either way.
Would you like the points?
Does not matter to me either way.
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.
ASKER
Enjoy!!!
Tom
Tom
OK, thanks very much.
ASKER
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(TempConnecti
SqlDataAdapter TempDataAdapter = new SqlDataAdapter(strTempSQL,
DataSet TempDataSet = new DataSet();
TempDataAdapter.Fill(TempD
DataTable TempDataTable = TempDataSet.Tables["Temp"]
SqlCommandBuilder TempCmdBuilder = new SqlCommandBuilder(TempData
foreach (DataRow myDataRow in TempDataSet.Tables["Temp"]
{
try
{
SelfEmployedRaw = myDataRow.IsNull("self-emp
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
break;
default:
ActiveMilitary = 1;
break;
}
switch(WorkForRelativeRaw)
{
case("No"):WorkForRelative
break;
case("Yes"):WorkForRelativ
break;
default:
WorkForRelative = 1;
break;
}
switch(type)
{
case("SelfEmployed"):Final
break;
case("ActiveMilitary"):Fin
break;
case("WorkForRelative"):Fi
break;
default:
FinalAnswer = 1;
break;
}//end switch
}//end try
catch(Exception e)
{
System.Diagnostics.Debug.W
}
}
return FinalAnswer;
}