Wrox Programmer Forums
|
Visual Studio 2008 For discussing Visual Studio 2008. Please post code questions about a specific language (C#, VB, ASP.NET, etc) in the correct language forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Visual Studio 2008 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old April 16th, 2010, 02:06 PM
Registered User
 
Join Date: Apr 2010
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default 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
 
Old April 17th, 2010, 07:48 PM
Registered User
 
Join Date: Apr 2010
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I found the answer. Please let me know if this is going to break anything.

In the properties of the data set, I found an option called Enforce Constraints, and I set it to false.

I am now able to save to the database without specifying an EmployeeID

Last edited by PhillD; April 19th, 2010 at 01:20 PM..





Similar Threads
Thread Thread Starter Forum Replies Last Post
Linq to Sql - Retrieving the value of an identity column BEFORE inserting new row jmartarelli BOOK: Professional LINQ 2 March 11th, 2011 04:42 PM
Linq to Sql - Retrieving the value of an identity column BEFORE inserting new row jmartarelli LINQ 2 August 4th, 2010 12:59 PM
Linq to Sql - Retrieving the value of an identity column BEFORE inserting register jmartarelli BOOK: Professional ADO.NET 3.5 with LINQ and the Entity Framework ISBN: 978-0-470-22988-0 0 July 17th, 2009 04:33 PM
identity column rohit_sant SQL Language 4 June 6th, 2005 08:27 AM
Identity column jbenson001 SQL Server 2000 5 April 12th, 2005 02:01 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.