Question Form Addnew -> primary key -1?

davken69

New member
Joined
Aug 1, 2010
Messages
3
Programming Experience
1-3
I've created an overview form witrh a list of customers. When the user wants to add a new customer, i use the addnew() function.

In the "add" screen an empty card is shown to be filled in by the user. When entering the new data, the primary key (auto number) stays -1? I thought it would change when the form is dirty?

I use NET 4.0 on a Access db. The CustomerID is primary key and auto number.

On the overview screen (after refresh) it is shown correctly.

Why doesn't the ID on my add form change to the new ID?
 
-1 is just a temporary Id, it wil lbecome proper when the record is saved to the DB. Tip: don't show users primary keys - they shouldnt need to know them in most cases
 
Yes i know it's a temporary id, but the problem is, after saving the form when you go back into edit mode the id is still -1, and when you try to save it the second time it'll raise an error because ID -1 is invalid!

I need the ID for updating, printing, searching stuf.. The ID field is not updatable and disabled on the form.

Anyway, this remains an issue :s
 
You're probably using Access as your database, or you've not ticked the "refresh The Dataset" option in the advanced config of the tableadapter
 
That's the problem, this option isn't available.. All other options are selected, but the "refresh data table" is disabled..
Any idea?
 
.NET isnt capable of refreshing the dataset with the database technology youre using. Try using SQLServer or Oracle free editions or, if the db tech youre using supports stored procedures, use stored procedures and return the ID as an OUT parameter

You can also consider making your primary key based on the data (e.g. CarRegistrationNumber) rather than an autoincrementing number
 

Latest posts

Back
Top