Search code examples
c#.netwinformsms-access-2010auto-increment

Pulling a list of Access table primary IDs into an array


I am using Visual Studio 2012 and Access 2010 with table adapters. This is for a school project.

I am currently developing a system in C# that uses an Access database with the table CUSTOMER which has a one to many relationship to the table VEHICLE. This is so one customer can be associated with many vehicles.

When entering a vehicle into the system, there is a required combobox that shows the names of all the customers in the system to associate that vehicle to(a vehicle MUST be associate with a customer).

My problem is that the CUSTOMER table uses auto-increment, so when a customer is deleted, the customer ids are no longer necessarily sequential. The logic for my combobox assumes that the top customer name is customer id 1, the second is 2, and so on. This is causing inconsistency's in my application.

My idea to fix this problem was to load all the customer ids from the customer table into an array in order at run time and then using that array as a reference(obviously updating it with added and deleted customers). However, I'm not sure how to code stepping through the table to get the ids or even if this is the best solution. Any thoughts?


Solution

  • When you load your customers. Set the value field to the customerID and the text field to the customerName field