Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Is it possible to get scope_identity without a stored procedure?

Reply
Thread Tools

Is it possible to get scope_identity without a stored procedure?

 
 
jm
Guest
Posts: n/a
 
      10-23-2006
I am using the generated SQL from VS using the DAL. After my INSERT it
has the select...scope_identity().

Is there any way to get the value of my new id field from this select
after the insert?

I thought it might be using the iteminserted even or the iteminserting
event, but I can't figure it out.

Do I have to write a custom insert and use the BLL and return a scalar?
If so where do I get that scalar from (what event is it wrapped in)?

Thank you for any help.

 
Reply With Quote
 
 
 
 
Eliyahu Goldin
Guest
Posts: n/a
 
      10-24-2006
Yes, it is possible. All you need to do is to run the insert and the select
statement in the same batch:

insert ...;select ...scope_identity()

Run is with ExecuteScalar method.
--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]


"jm" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) ups.com...
>I am using the generated SQL from VS using the DAL. After my INSERT it
> has the select...scope_identity().
>
> Is there any way to get the value of my new id field from this select
> after the insert?
>
> I thought it might be using the iteminserted even or the iteminserting
> event, but I can't figure it out.
>
> Do I have to write a custom insert and use the BLL and return a scalar?
> If so where do I get that scalar from (what event is it wrapped in)?
>
> Thank you for any help.
>



 
Reply With Quote
 
 
 
 
jm
Guest
Posts: n/a
 
      10-25-2006

jm wrote:
> I am using the generated SQL from VS using the DAL. After my INSERT it
> has the select...scope_identity().
>
> Is there any way to get the value of my new id field from this select
> after the insert?
>
> I thought it might be using the iteminserted even or the iteminserting
> event, but I can't figure it out.
>
> Do I have to write a custom insert and use the BLL and return a scalar?
> If so where do I get that scalar from (what event is it wrapped in)?
>
> Thank you for any help.


I was able to get the value from the Inserted event of the
ObjectDataSource:

protected void ObjectDataSource1_Inserted(object sender,
ObjectDataSourceStatusEventArgs e)
{
int employeeid = Convert.ToInt32(e.ReturnValue); //get the new
employeeid for this scope_identity()
.......

 
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
how to get scope_identity here? Luc ASP .Net 3 09-14-2009 02:32 PM
Returning SCOPE_IDENTITY from SQLDataSource and DetailsView David Lozzi ASP .Net 1 03-30-2007 08:08 PM
Using Scope_Identity with a SQLDataSource in ASP.NET blouie ASP .Net 0 01-05-2007 04:08 PM
How do I retrieve the scope_identity() with the tableadapter? needin4mation@gmail.com ASP .Net 2 10-13-2006 01:14 PM
scope_identity() issues. Mr Newbie ASP .Net 4 01-16-2006 05:33 AM



Advertisments