I'm making an assignment for school and it involves creating an application with certain restrictions on how to create it. Such as having a set amount of methods. I figured i'd say that before posting code that looks unoptimized, and can infact be done with less methods.
Anyway, currently i have a Northwind class, that handles everything that comes from the Database and in this case, creates a list filled with the Shipper object, then i use another Northwind Method to convert that to a queue. (this is what i mean with unoptimized, i could just use a queue from the get-go but i'm not allowed to.) However, when i use it it comes up with a very common error. But i can't figure out why...
class Northwind
{
public Queue<Shipper> Queue { get; set; }
public List<Shipper> GetList()
{
var con = new SqlConnection("Data Source=DESKTOP-G5VBFCN;Initial Catalog=Northwind;Integrated Security=True");
var cmd = new SqlCommand("SELECT CompanyName, Phone FROM Shippers",con);
con.Open();
var reader = cmd.ExecuteReader();
var ShipList = new List<Shipper>();
while (reader.Read())
{
var s = new Shipper
{
CompanyName = reader["CompanyName"].ToString(),
Phone = reader["Phone"].ToString()
};
ShipList.Add(s);
}
con.Close();
return ShipList;
}
public Queue<Shipper> GetQueue(List<Shipper> List)
{
Queue<Shipper> ShipperQueue = new Queue<Shipper>(List);
return ShipperQueue;
}
}
}
And i use the class in my Form1.cs
public partial class Form1 : Form
{
Northwind db;
Shipper Shipper;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
db.Queue = db.GetQueue(db.GetList());
}
Do please notice that the Northwind db; is actually underlined in green. I just started learning OOP. Thanks for taking the time to look at my code.