There are two SqlHelper classes and a DishesTypes class used as DAL
public class SqlHelper{ public static SqlDataReader ExecuteReader(string procedure, params SqlParameter[] commandParameters){ using (var connection = new SqlConnection(ConfigurationManager.ConnectionStrings["DefaultConnection"].ConnectionString)) using (var command = new SqlCommand(procedure, _connection)){ command.CommandType = CommandType.StoredProcedure; command.Parameters.AddRange(commandParameters); return command.ExecuteReader(); } } } } public class DishesTypes{ public static SqlDataReader DishesTypesSelectAll(){ return SqlHelper.ExecuteReader("DishesTypesSelectAllRows");//название хранимой процедуры } } And there is a class DishedTypes which is used as BLL
public class DishesTypes { public int DishTypeId { get; set; } public string DishType { get; set; } public static List<DishesTypes> DishesTypesSelectAll() { IDataReader dr = DataAccessLayer.DishesTypes.DishesTypesSelectAll(); List<DishesTypes> dishesTypesList = new List<DishesTypes>(); while (dr.Read()) { DishesTypes myDishesTypes = new DishesTypes { DishTypeId = (int)dr["DishTypeId"], DishType = (string)dr["DishType"] }; dishesTypesList.Add(myDishesTypes); } return dishesTypesList; } } An error occurs during the execution of this code section.
while (dr.Read()) The reason for this is that the connection is already closed at this point and you need to reopen it. What is the best way to change the implementation of classes by adhering to the DAL and BLL layers in order for it to work?
DataTable. ForSqlDataReaderyou need an open connection. - Igor