protected static object ReadList(SQLDataReader dr) { List <User> retVal = new List <User>(); while (dr.Read()) { User temp = new User(); temp.Prop1 = dr.GetString("Prop1"); temp.Prop2 = dr.GetInt("Prop2"); retVal.Add(temp); } return(retVal); }
private static List <Product> InitializeCollectionOld(string tableName) { List <Product> list = new(); OpenDataBaseConnection(); SQLCommand = new SqlCommand($"SELECT * FROM {tableName}", SQLConnection); SQLDataReader = SQLCommand.ExecuteReader(); while (SQLDataReader.Read()) { list.Add(new Product { Id = Convert.ToInt32(SQLDataReader["id"]), Name = SQLDataReader["name"].ToString(), Price = Convert.ToDecimal(SQLDataReader["price"]) }); } CloseDataBaseConnection(); return(list); }