alexands
Posts: 11
|
| Posted: 11/07/2006, 12:51 PM |
|
Hi,
I have a record form where I am inserting values into my table. My table (MSSQL) has an identity column. How can I retreive the identity value of the record I just inserted. I have seen a few posts that somewhat "describe" what to do, but I have yet to see anything that shows specifically what code to create and where to create it. I'm using C#.
Thanks,
Scott
|
 |
 |
Edd
Posts: 547
|
| Posted: 11/08/2006, 4:06 AM |
|
Try
Getting the @@IDENTITY from SQL. This must be performed IMMEDIATELY after the insert before the connection is closed - otherwise the information is lost.
Edd
_________________
Accepting and instigating change are life's challenges.
http://www.syntech.com.au |
 |
 |
alexands
Posts: 11
|
| Posted: 11/10/2006, 10:12 AM |
|
Edd,
Thanks for the tip. I figured this is what I needed to do. However, because I am not familiar with the data object model of CCS, can you provide a specific code example?
Thanks,
Scott
|
 |
 |
peterr
Posts: 5971
|
| Posted: 11/10/2006, 11:01 AM |
|
Scott,
The "Multi-step Registration" example in CCS Example Pack has working example of this specific functionality (only @@IDENTITY is replaced there with non database specific SQL).
_________________
Peter R.
YesSoftware Forums Moderator
For product support please visit http://support.yessoftware.com |
 |
 |
JayEdgar
Posts: 77
|
| Posted: 11/16/2006, 7:37 PM |
|
There is an exception to this: If you have triggers running in SQL Server. In this case, it will return the identity of the record changed as a result of the trigger, not your change. In this case, I often write a unique value to an unused/lesser-used field, then search for that value after the insert, get the PK and clear the temp field.
99.9% of people won't need to know this, and for that .1% person who does, cheers,
Jay
|
 |
 |
|