How do you autoincrement primary key in Visual Studio Databse

Posted on 2009-04-22
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


    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 26

    Assisted Solution

    by:Chris Luttrell
    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

    Thank You

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Find Ransomware Secrets With All-Source Analysis

    Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

    Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
    In this article we will get to know that how can we recover deleted data if it happens accidently. We really can recover deleted rows if we know the time when data is deleted by using the transaction log.
    Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
    In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor ( If you're interested in additional methods for monitoring bandwidt…

    759 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

    Need Help in Real-Time?

    Connect with top rated Experts

    8 Experts available now in Live!

    Get 1:1 Help Now