I have a function which performs an SQL query. Depending on a registry value, it will either hit SQL Server or SQL Server Compact Edition. If it is using SQL Server CE, the line setting the recordSet variable should read like this:
SqlCeDataReader recordSet = da.ExecuteSQLCommand(selectCommand);
For SQL Server, it should read like this:
SqlDataReader recordSet = da.ExecuteSQLCommand(selectCommand);
I am trying to put all this in an if/then statement at the beginning at the function but cannot seem to figure out how to set the Type within the if/then. Here is my (partial) code:
public static string SqlQuery(string selectCommand, int regval)
{
var recordSet = null;
string selectCommand = "select * from whatever";
if (regval == 0)
{
SqlDataReader recordSet = null;
}
else
{
SqlCEDataReader recordSet = null;
}
recordSet = da.ExecuteSQLCommand(selectCommand);
}
The problem is that unless I declare the recordSet variable before the if/else, I cannot use it after. However, if I declare it before the if/else, I cannot change the type.