I've had this problem before too. The reason is that reader("M_ItemGroupID").ToString is not a string, it's a pointer to an object reference and the item in the listbox is not a string, it's an object. When the reader moves onto the next row, the pointer is then pointing to a reference with a different value, rather than what was there during the previous loop, so the object that gets displayed in the listbox is now something completely different than what you wanted to put in there.
Why it works this way, I don't know - it strikes me as somewhat silly behaviour that likely has a boring technical rationale behind it which only four people in the world care about.
To fix it, change your code to this:
This creates new strings each time through the loop and adds those values to the listbox, so each item is referencing something different and they don't change as the reader moves onto the next row.Code:while reader.Read dim sCode as String = reader("Itemcode").ToString dim sGroupID as String = reader("M_ItemGroupID").ToString itemgroup.Itemcode = sCode itemgroup.ItemGroupID = sGroupID myList.add(itemGroup) end while




Reply With Quote