Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > DetailsView - How do I get the new record's ID after Insert?

Reply
Thread Tools

DetailsView - How do I get the new record's ID after Insert?

 
 
MU
Guest
Posts: n/a
 
      01-26-2009
Hello,

I have a DetailsView on my form and I have a CheckBoxList that the
user can use in Insert mode. I need to take the values that were
selected from the CheckBoxList and insert them into another table
along with the NEW record id that is generated from the Insert from
the DetailsView.

How do I get access to the new record's ID after you click Insert so
that I can do the update to the other table? Is there a function that
I should use and what value do I check?

Thoughts?
 
Reply With Quote
 
 
 
 
Paul Shapiro
Guest
Posts: n/a
 
      01-26-2009
You retrieve the value (assuming your're using SQL Server) with
SCOPE_IDENTITY. From SQL BOL: "Returns the last identity value inserted into
an identity column in the same scope. A scope is a module: a stored
procedure, trigger, function, or batch. Therefore, two statements are in the
same scope if they are in the same stored procedure, function, or batch."

So either include "Select Scope_Identity() as newID;" in the batch following
your Insert statement, or include both Insert statements in the batch:
Insert Table1 (...);
Insert Table 2 (foreignKeyID, ...) Values (Scope_Identity(), ...);

"MU" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Hello,
>
> I have a DetailsView on my form and I have a CheckBoxList that the
> user can use in Insert mode. I need to take the values that were
> selected from the CheckBoxList and insert them into another table
> along with the NEW record id that is generated from the Insert from
> the DetailsView.
>
> How do I get access to the new record's ID after you click Insert so
> that I can do the update to the other table? Is there a function that
> I should use and what value do I check?


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
Make new record current in DetailsView after Insert Hanno ASP .Net Datagrid Control 0 08-04-2006 11:00 PM
insert new record in detailsview - how to get master id =?Utf-8?B?SmF5RA==?= ASP .Net 1 07-10-2006 07:13 PM
if instance variable get initialize after assigning some values or after constructor then when does static variable get initialize Tony Morris Java 3 02-04-2006 08:39 AM
DetailsView - Changing to Insert Mode (Not By Using the Insert Button In the DetailsView Control) Feege ASP .Net Web Controls 0 12-20-2005 12:28 AM



Advertisments