Re: Need Help with Select @@ Identity

Tech-Archive recommends: Fix windows errors by optimizing your registry



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.

.



Relevant Pages

  • Re: Best Practices - Connecting to Oracle from a fat client
    ... logic is on the client, and not on a centralized server, connection pooling ... Do not open a single connection ...
    (microsoft.public.dotnet.framework.adonet)
  • Re: Need Help with Select @@ Identity
    ... that all these steps should be performed in a single connection. ... connection specific command. ... Dim Conn As New OleDbConnection ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: singe thread per connection
    ... for single connection. ... I need to open arround minimum of 500 telnet ... InputStream is =new BufferedInputStream); ...
    (comp.lang.java.programmer)
  • RE: Duplicate Connections
    ... I just ran a test using the following code and it created a single connection ... CategoryName"; ... > I am using the SQLConnection object to establish a connection a SQL Server ...
    (microsoft.public.dotnet.framework.adonet)
  • Re: Need Help with Select @@ Identity
    ... Right now I have steps 1-4 completed in the .aspx file then my ... How do I complete this in one connection? ... There will not be a risk of getting the wrong catID as there will ... that all these steps should be performed in a single connection. ...
    (microsoft.public.dotnet.framework.aspnet)