It is bad practice to use
if ()
else if ()
without a final else statement even if you think your variable will never have an unexpected value.
What will happen if your defined statements are not met is that the program runs through to the statement after the last else if.
Either add an else statement that takes care of this undefined case or change to a switch statement with a default statement.
if (radio.SelectedValue == "0")
{
sql = ...
}
else if (radio.SelectedValue == "1")
{
sql = ...
}
else
{
throw new Exception(string.Format("Selected value is undefined: {0}.", radio.SelectedValue));
}
or
switch (radio.SelectedValue)
{
case 1: sql = ...; break;
case 2: sql = ...; break;
default: throw new Exception(string.Format("Selected value is undefined: {0}.", radio.SelectedValue));
}