How do you autoincrement primary key in Visual Studio Databse

Posted on 2009-04-22
Medium Priority
Last Modified: 2012-05-06
i have a Database in Visual Studios with the following fields

OrderID char(10)
CustomerID char(10)
CardID char(10)

when a new record is put in i want the orderID to increment by itself information entered into database is added
on a webpage using textboxes. the language i am using is C#

Question by:MUDDY_123
LVL 14

Accepted Solution

GiftsonDJohn earned 1000 total points
ID: 24207059

Make the OrderID column as Identity. It will have the option for auto incrementing the value. You can get the identity option from orderid column properties.
LVL 27

Assisted Solution

by:Chris Luttrell
Chris Luttrell earned 1000 total points
ID: 24207149
I assume your database is SQL 2008, you can set a filed in the table to be an IDENTITY field but its type must be of data type int, bigint, smallint, tinyint, or decimal or numeric with a scale of 0, and constrained to be nonnullable.  If you can change OrderID to be an Int you can use that.

Author Closing Comment

ID: 31573403
Thank You

Featured Post

Prep for the ITIL® Foundation Certification Exam

December’s Course of the Month is now available! Enroll to learn ITIL® Foundation best practices for delivering IT services effectively and efficiently.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article shows the steps required to install WordPress on Azure. Web Apps, Mobile Apps, API Apps, or Functions, in Azure all these run in an App Service plan. WordPress is no exception and requires an App Service Plan and Database to install
By, Vadim Tkachenko. In this article we’ll look at ClickHouse on its one year anniversary.
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question