I keep getting an error "not all code paths return a value." I've tried placing the return statement in several places to resolve the issue. Obviously I don't understand how to resolve this seemingly simple and common problem.
Also I'm using a using statement for the datareader and a try catch block for my connection object. Does this look ok? It seems a bit sloppy to use to approaches to the same thing but i'm not sure I can do my error handling with a using statement.
Here is the method.
public DataTable GetETLClientList(string ConnectionString)
{
// Set up parameters in parameter array
SqlParameter[] arParms = new SqlParameter[0];
//arParms[0] = new SqlParameter("@Email", SqlDbType.VarChar);
//arParms[0].Value = Email;
SqlTools tools = SqlTools.CreateAndConnectSqlTools(ConnectionString);
try
{
SqlCommand command = new SqlCommand();
command.CommandType = CommandType.StoredProcedure;
command.CommandText = "GetETLClientList";
//command.Parameters.AddRange(arParms);
//SqlParameter param = command.Parameters.AddWithValue("@param", value);
DataTable dtETLClient = new DataTable("ETLClient");
using (SqlDataReader dataReader = tools.ExecuteDataReader(command))
{
// A simple google search will show numerous articles and messageboards explaining that a datareader should not be passed between tiers
// While it is not a bad thing, it is not a best practice and could cause problems closing the datareader.
// To resolve this problem, i convert the datareader to a datatable.
dtETLClient.Load(dataReader);
dataReader.Close();
}
return dtETLClient;
}
catch (SqlException ReadError)
// catch (Exception ex)
{
//throw;
pErrorMessage = ReadError.Message.ToString();
pErrorNumber = ReadError.Number;
pErrorClass = ReadError.Class;
pErrorState = ReadError.State;
pErrorLineNumber = ReadError.LineNumber;
pTransactionSuccessful = false;
}
finally {
tools.Disconnect();
}
}