Last time I had a similar question, but we figured out if initialize and set a value for the variable before the logic statement then I can use the value that was generated within the logic statement.
This time, I want to call one of two method overloads depending on if the connection string is empty or not. Like so.
if (ConnectionString != "") // if there is something in the config file work with it
{
SqlConnection dataConnection = new SqlConnection(ConnectionString);
}
else
{
SqlConnection dataConnection = new SqlConnection();
}
try {
// ...
The problem is that anything in the try block fails because it does not know about the dataConnection.
How can do I do this in a way to make it work?
elsecondition? Crash?