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 466535
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T23:29:24+00:00 2026-05-12T23:29:24+00:00

I have a collection List<Employee> employees; I use a DataTable, and load all the

  • 0

I have a collection

List<Employee> employees;

I use a DataTable, and load all the records (from MDB table) when Form1.Loads, and add these records to the List (Collection) so I work with them in memory.

Now, when I add a new employee to the collection, I should add it also to the mdb table… so I do:

DataRow rowemployee = Program.tblEmployee.NewRow();
rowemployee["name"] = tb_Name.Text;
rowemployee["address"] = tb_Address.Text;
//...all the other fields
Program.tblEmployee.AddRow(rowemployee);

The IDE throws an error regarding “id” column must not have a null value or must not be empty.
As the mdb table has an id column, type number, autoinc, how should I fix the Employee class, and the DataTable/Collections methods, so the id column is “ignored” when adding new rows?

Thanks

  • 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-05-12T23:29:24+00:00Added an answer on May 12, 2026 at 11:29 pm

    The first problem is that while the id column is auto-incremented in your database, the DataColumn object corresponding to it in your DataTable isn’t set up to auto-increment. You need to set its AutoIncrement, AutoIncrementSeed, and AutoIncrementStep properties.

    Once you do this, you’ll run into the second problem, which is that you have two different auto-increment seeds: the one in your database and the one in your DataTable. Even if those two seeds start out at the same value, it’s trivial for them to get out of sync: add a row to your DataTable and a different row to your database table, and now you have two different rows with the same ID.

    This is a common problem, and its common solution is to have a different numbering sequence for rows that are added to the DataTable. Commonly this is done by setting the seed to 0 and the step to -1, so that all rows that you add to the DataTable have IDs that are less than 0. (This of course assumes that all IDs in your database are greater than 0.) This means that there’s no chance of an ID collision between rows added in the database and rows added to the DataTable.

    Then, when you actually update the database from the DataTable, after you insert the row into the database and its real ID gets assigned, you change the ID in the DataRow to the correct value. If the row is participating in data relations as a parent, the DataColumn has to have cascading updates set, so that changing the ID in the parent row from its temporary local value to its permanent value also changes the IDs in the related child rows.

    One of the many reasons to use typed data sets and table adapters is that all of this work is done for you automatically. But if you’re not using table adapters, you’ll have to do it yourself. There’s a pretty good example of this in the ADO documentation

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

Sidebar

Related Questions

I have a list: Collection users which has around 100K+ records of users (all
I have Collection List<Car> . How to compare each item from this collection with
I have sorted collection (List) and I need to keep it sorted at all
I have a List<Employees> collection that I am trying to select Active employees on.
I have table employee I retrieve the columns as select emp_name,emp_add from employee while(iResultSet1.next())
I have a collection: List<Car> cars = new List<Car>(); Cars are uniquely identified by
This is a long shot, I know... Let's say I have a collection List<MyClass>
I have a collection (or list or array list) in which I want to
I have a list/collection of objects that may or may not have the same
I have a collection like this List<int> {1,15,17,8,3}; how to get a flat string

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.