Below is working code from my application.
All I'm pulling back from the table is is IDX and an associated string.
ls is a List<T> of the same class tmpINC is an instance of.
When I test tmpINC before adding it to the list, the data in IDX and Name is correct.
However in the loop I do after (to check the data with the MessageBox.Show) every record is the same (the last record added).
What am I missing here.
// Fill the List ...
if (ds.Tables[0].Rows.Count > 0)
{
for (int x = 0; x < ds.Tables[0].Rows.Count; x++)
{
tmpINC.IDX = int.Parse(ds.Tables[0].Rows[x][0].ToString());
tmpINC.Name = ds.Tables[0].Rows[x][1].ToString();
ls.Add(tmpINC);
}
for (int x = 0; x < ls.Count; x++ )
{
MessageBox.Show(ls[x].IDX.ToString() + "\n" + ls[x].Name);
}
}
Thanks for looking guys.