示例#1
0
    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);
    }
示例#2
0
        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);
        }