Click here to Skip to main content
15,888,527 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi All,

I am using Sql Server as database in my application. In which i am using coulmn name - ID (primary key and also IsIdentity=Yes) in table.

So I need to show the ID in form before saving it.

How is it possible?

Regards!
Aman
Posted

SELECT IDENT_CURRENT('Yourtable_name') will give you last value generated by identity column.
See Here[^]
 
Share this answer
 
I'm not sure exactly what you are trying to do, but I assume you have a problem because this is an identity column and you need the identity value in your form before you save the record?

In short, you can't.

An Identity value is assigned by the database system when the record is saved, to prevent it being duplicated in any way: only the database can assign the value, and only when teh record is first saved. Attempts to assign it yourself, will cause an error.

All you can do is save the record, read it back to get the ID and then display it.

If you actually need the ID value, then I would strongly suggest you use GUID values instead: these are assigned by your code rather than the database and can be pre-generated and never used if the data is not saved.
 
Share this answer
 

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