List problem ... need a second set of eyes....

Discussion in 'C#' started by Zinderin, Aug 28, 2010.

  1. Zinderin

    Zinderin New Member

    Joined:
    Aug 28, 2010
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    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 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.
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice