Hello, I'm creating a simple inventory/POS web application for our company. I created a class called InventoryItems and created a list of InventoryItems named items. I created a SqlDataReader to read in the database and add the database to the list items. My problem is that when the while loop is finished, the list items is filled with only the last record in the database. (i.e. there are 166 items and they are all the same). Any help is greatly appreciated. Below is the portion of code I'm having a problem with.
SqlDataReader r = null;
SqlCommand cm = new SqlCommand("Select * From Inventory", new SqlConnection("removed for privacy reasons"));
cm.Connection.Open();
r = cm.ExecuteReader();
InventoryItem temp = new InventoryItem();
while (r.Read())
{
temp.ID = int.Parse(r["ID"].ToString());
temp.UPC = r["UPC"].ToString();
temp.Description = r["Description"].ToStri ...
Go to the complete details ...