Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: ASP.NET SQL-Server
How to autogenerate Ticket number and save into database?
This question regarding help desk ticket creation into any project.
Posted 13-Mar-13 2:46am
Edited 13-Mar-13 3:23am
Mike Meinz22.8K
v2
Comments
ryanb31 at 13-Mar-13 7:50am
   
Write the SQL to do it, or use an identity field. Then write code in ASP.Net. What do you actually need help with?
ThePhantomUpvoter at 13-Mar-13 8:41am
   
How do you expect us to know what you think your "ticket number" looks like?
Anuja Pawar Indore at 13-Mar-13 9:09am
   
Are you looking for Capcha? or Simple number....
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

In your database schema have one column set up to use the IDENTITY property
e.g.
create table myTable(
TicketID int not null IDENTITY(1,1)
-- other columns ...
)
This will automatically create a TicketID starting at 1 (1,1) and incrementing by 1 each time a row is added (1,1). It will automatically handle any rows that are deleted from the table ensuring that the TicketID is always unique.
 
See this link[^] for the documentation
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

Let SQL Server do the work for you.
 
1. Declare a Primary Key column (TicketNumber) in the "Ticket" table of INT or BIGINT Data Type with Column Properties Identity Specification IsIdentity set to Yes, Identity Increment set to 1 and Identity Seed set to 1.
CREATE TABLE YourTableName (
TicketNumber INT NOT NULL IDENTITY(1,1),
 
-- ...
-- The remainder of your table's columns go here
-- ...

)
or
CREATE TABLE YourTableName (
TicketNumber BIGINT NOT NULL IDENTITY(1,1),
 
-- ...
-- The remainder of your table's columns go here
-- ...

)
2. After an INSERT of a new "Ticket" row, use the SCOPE_IDENTITY function to get the Primary Key of the inserted row. That value is the "Ticket Number".
 
* See Retrieving Identity or Autonumber Values (ADO.NET)[^].
* See example of retrieving SCOPE_IDENTITY at Obtaining a Single Value from a Database[^].
  Permalink  
v6

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Mathew Soji 330
1 BillWoodruff 260
2 Sergey Alexandrovich Kryukov 240
3 OriginalGriff 216
4 Afzaal Ahmad Zeeshan 208
0 OriginalGriff 6,168
1 Sergey Alexandrovich Kryukov 5,853
2 DamithSL 5,028
3 Manas Bhardwaj 4,539
4 Maciej Los 3,845


Advertise | Privacy | Mobile
Web01 | 2.8.1411019.1 | Last Updated 13 Mar 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100