"Vishal Somaiya" wrote...
> I get a problem when I try to add the object that I created
> to the arraylist. It seems to be adding each one, but when
> I view the results of the list, it shows the last object
> passed in for each object stored within the Arraylist.
You're not adding a *new* object for each iteration, but the same object
every time. Inside the iteration, you change the values of *that* object.
I trim down you're code, so you might see it more clearly:
> ClientData objClientData = new ClientData(); // <--
> ArrayList objArrayList = new ArrayList();
> while (_clientCode.MoveNext() && _clientName.MoveNext()
> && _clientDetails.MoveNext())
[quoted text clipped - 5 lines]
> objArrayList.Insert(j,objClientData);
> }
What you can do is simply to move the instantiation inside the iteration:
ArrayList objArrayList = new ArrayList();
while (_clientCode.MoveNext() && _clientName.MoveNext()
&& _clientDetails.MoveNext())
{
ClientData objClientData = new ClientData(); // <--
objClientData.clientCode = _clientCode.Current.Value.ToString();
objClientData.clientName = _clientName.Current.Value.ToString();
objClientData.clientDetails = _clientDetails.Current.Value.ToString();
objArrayList.Insert(j,objClientData);
}
// Bjorn A
Vishal Somaiya - 12 Aug 2005 09:09 GMT
Thanks Bjorn
Works like a dream!
Vishal
> "Vishal Somaiya" wrote...
>
[quoted text clipped - 38 lines]
>
> // Bjorn A