SQL Identity Column in Form
I have setup a simple table in SQL 2005 with 2 fields, EmployeeID and EmployeeName. EmployeeID is a primary key and an identity field (seed 1 increment 1).
A created a new form and setup a data source added the 2 fields to the form by clicking and dragging from the data source. Visual studio setup the TableAdapter, DataSet and BindingSource.
I am able to create and save records from the form to the database.
When I click the new button, the EmployeeID column shows a negative number. When I save the record, the EmployeeID is changed to it's real (saved) database value. I understand why negative numbers are used and that I can change them to positive but I do not want any number to appear in the EmployeeID column until the record is saved. So I turned off the Identity setting in the dataset and set it to allow DBNull. This stopped the ID from being created in the form but when I save, I get an EndEdit Error that EmployeeID cannot be blank.
When I edit the table directly in Visual Studio or in SQL, I am able to enter an Employee Name without specifying an ID. After I move off the row, an ID is generated and saved directly in the table
Why does the form make me specify an ID when the database doesn't require it?
Thanks
|