Generating sequence number in C# -


i working on asp.net using c# want generate sequence id should this:

elg0001 , elg0002, ... 

elg prefix , 0001 should in sequence

i using sql server 2005

this id generated , added database. how can this?

can me coding?

here's simple id generator sql server:

create table idseed (     id int identity(10001,1) ) go  create procedure newsequenceid (     @newid char(7) out ) begin     insert idseed default values      select @newid = 'elg' + right(cast(scope_identity() nvarchar(5)), 4) end go  /*  * test newsequenceid proc  */ declare @testid char(7)  exec newsequenceid @testid out  select @testid 

the idseed table continue accumulate rows. not issue, if problem can purge table script on regular basis. part left call procedure c# code , retrieve value of @testid parameter.

this example based on question: sequence not expected exceed 9999 elements. have modify code support larger sequence ids.

note transaction not necessary in procedure newsequenceid because scope_identity() function returns values current sql session. if thread performs near-simultaneous insert, value returned scope_identity() won't affected.


Comments

Popular posts from this blog

c++ - How do I get a multi line tooltip in MFC -

asp.net - In javascript how to find the height and width -

c# - DataTable to EnumerableRowCollection -