Re: Need Help with Select @@ Identity
- From: Tushar <Tushar@xxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Sun, 15 Apr 2007 09:18:02 -0700
Hi Pink,
There is a work around way. But that is a bad practise. As you said only
one user will be using this application you can do this.
Insteat of writing SELECT @@IDENTITY in your code , you can write SELECT TOP
CATID FROM Categories . Since it is an auto increment , you'll always get the
highest value which would be same like SELECT @@IDENTITY . But this would
only work if one user is using the app.
This is a bad practise. I would suggest you to follow SELECT @@IDENTITY and
that too in a single batch.
--
Regards,
Tushar
MCTS - .NET 2.0 Web App
"PinkBishop" wrote:
Tushar,.
I understand what you are saying about the need for everthing to
happen under a single connection.
Right now I have steps 1-4 completed in the .aspx file then my
attempt was to complete 5-6 with the .aspx.vb code behind. Now I
realize that can't be done.
How do I complete this in one connection?
or
Is there a way to get the primary key of the last record inserted into
table 1 so to insert into table 2?
Now that I think more, I still need the value from the dropdown as
well.
So, after the insert into table 1 is there a way to call the catID and
imgID from Table 1 and insert into table 2?
There will not be a risk of getting the wrong catID as there will
always be only 1 person entering into the db at a time. I do say
always lightly though.
TRU
On Sat, 14 Apr 2007 22:38:02 -0700, Tushar
<Tushar@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote:
Hi
It's ok. You will learn soon.
You are right . You performed steps 1-4 and then 5-6. But the problem is
that all these steps should be performed in a single connection.
From the code that you have written what i feel is that you
open a connection
perform steps 1-4
close a connection
open a connection
perform steps 5-6...
close the connection
In this case "select @@IDENTITY" won't work because it is connection
specific. All the steps need to be performed under a single connection
object.
The steps 5-6 are been performed when the item has already been inserted.
When you create a new connection to the database , SELECT @@IDENTITY doesn't
work. It doesn't know which value was inserted last.
Just try and perform all these steps in a single go and I am sure it'll
work. Even then if you face a problem feel free to get back to me. I'll
explain it to you through mail or chat.
- Follow-Ups:
- Re: Need Help with Select @@ Identity
- From: PinkBishop
- Re: Need Help with Select @@ Identity
- References:
- Need Help with Select @@ Identity
- From: PinkBishop
- RE: Need Help with Select @@ Identity
- From: Tushar
- Re: Need Help with Select @@ Identity
- From: PinkBishop
- Re: Need Help with Select @@ Identity
- From: Tushar
- Re: Need Help with Select @@ Identity
- From: PinkBishop
- Need Help with Select @@ Identity
- Prev by Date: Re: integer validation
- Next by Date: Validation (Internet Explorer 6): Attribute 'target' is not a valid attributeof element 'frame'
- Previous by thread: Re: Need Help with Select @@ Identity
- Next by thread: Re: Need Help with Select @@ Identity
- Index(es):
Relevant Pages
|