Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9080867
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T20:10:30+00:00 2026-06-16T20:10:30+00:00

In my app I retrieve 3 rows of data from my database, I loop

  • 0

In my app I retrieve 3 rows of data from my database, I loop through the rows of data to assign the data to my customer object, then add the customer to a customer collection:

// new customer object to fill in loop and assign to collection
tracker.Customer myCustomer = new tracker.Customer();

// new customer collection object to fill later
Tracker.customerCollection  myCustomerCollection = new trackerCustomerCollection();

foreach (System.Data.DataRow drRow in dsResults.Tables[0].Rows) 
{
  myCustomer.CustomerID = Item["CustomerID"];
  myCustomer.FKBandID = Convert.ToInt32(drRow["FKBandID"]);
  myCustomer.FKSectorID = Convert.ToInt32(drRow["FKSectorID"]); 
  myCustomer.CustomerName = Convert.ToString(drRow["CustomerName"]);
  myCustomer.CustomerAddress = Convert.ToString(drRow["CustomerAddress"]);
  myCustomer.CustomerPhoneNumber = Convert.ToString(drRow["CustomerPhoneNumber"]);

  myCustomerCollection.Add(myCustomer);
}

The problem is that when I try to use the populated myCustomerCollection, the 3 Customer objects within the collection are all identical. Each instance of myCustomer is different as I iterate through the loop, but they change once added to myCustomerCollection. each item will be the same as the last item added.

If anyone can point me in the right direction, I’d be very grateful, I have used this principle in VB.NET with no issues, but I’m now forced to use C# and having real trouble finding the source of my problem.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T20:10:32+00:00Added an answer on June 16, 2026 at 8:10 pm

    This is because you’re creating 1 instance of your Customer object, and adding it to the list 3 times (modifying it each time you loop).

    If you move your new tracker.Customer() inside the loop, you’ll create 3 individual customer objects.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying out odata4j in my android app to retrieve data from a
I'm using MySQL Connector to retrieve data from a mySQL database to a .NET
Ok i need my app to retrieve data from a DB and display it
I'm trying to retrieve attachments from Mail.app through scriptingbridge. I'm using the following code
The headline says it all. At start of my app I retrieve data from
from 1 week if my gps app fail to retrieve signal (eg: testing in
My app is calling a web service to retrieve some data, and I want
How can I retrieve and copy all photos/videos from Photos app to my application
How can you retrieve your phone internal storage from an app? I found MemoryInfo,
I'm making a Phonegap app and need to retrieve some information from an external

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.