Click here to Skip to main content
15,886,110 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How to autogenerate Ticket number and save into database?
This question regarding help desk ticket creation into any project.
Posted
Updated 13-Mar-13 2:23am
v2
Comments
ZurdoDev 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?
[no name] 13-Mar-13 8:41am    
How do you expect us to know what you think your "ticket number" looks like?
Anuja Pawar Indore 13-Mar-13 9:09am    
Are you looking for Capcha? or Simple number....

In your database schema have one column set up to use the IDENTITY property
e.g.
SQL
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
 
Share this answer
 
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.
SQL
CREATE TABLE YourTableName (
TicketNumber INT NOT NULL IDENTITY(1,1),

-- ...
-- The remainder of your table's columns go here
-- ...

)
or
SQL
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[^].
 
Share this answer
 
v6

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900