RETIRIVAL OF AUTO GENERATED NUMBER

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

DEAR SIRS,

I AM DEVELOPING A SOFTWARE BY USING VB.NET AND SQLSERVER 2000 FOR A NETWORK ENVIRONMENT. I HAVE A BROBLEM THAT I HAVE A FIELD FOR PRIMERY KEY WHICH IS AUTO GENERATED. I NEED THAT WHEN THE FORM IS LOADED THE NEXT AUTO GENERATED NO SHOULD BE IN THE REQUIRED TEXTBOX. HOW TO GET THE NEXT NUMBER FROM SQLSERVER2000 TO TEXTBOX.

I WILL APPRICIAT YOUR COOPERATION.


MUSTAFA IRSHAD
 
Hi Mustafa,

I think that you should make a Select sentence with an order clause in it
and use a datareader.

http://msdn.microsoft.com/library/d...-us/cpguide/html/cpcontheadonetdatareader.asp

A better newsgroup to ask this question is
microsoft.public.dotnet.framework.adonet

But I hope this helps?

Cor

ps. A lot of people do not answer messages with uppercases, so if you are
able to avoid that I think that i better.
I AM DEVELOPING A SOFTWARE BY USING VB.NET AND SQLSERVER 2000 FOR A
NETWORK ENVIRONMENT. I HAVE A BROBLEM THAT I HAVE A FIELD FOR PRIMERY KEY
WHICH IS AUTO GENERATED. I NEED THAT WHEN THE FORM IS LOADED THE NEXT AUTO
GENERATED NO SHOULD BE IN THE REQUIRED TEXTBOX. HOW TO GET THE NEXT NUMBER
FROM SQLSERVER2000 TO TEXTBOX.
 
Mustafa,

The best way to do this is to use a stored procedure on the database that
when the procedure is finished doing its insert which generates the
auto-gen'd number for the primary key, use RETURN @@SCOPE_IDENTITY at the
end of your stored proc, and capture this as a return value in VB. Saves a
round trip to the DB server to go back and get the value using a large where
clause, and you don't have datareader overhead.

Aiax

MUSTAFA IRSHAD said:
DEAR SIRS,

I AM DEVELOPING A SOFTWARE BY USING VB.NET AND SQLSERVER 2000 FOR A
NETWORK ENVIRONMENT. I HAVE A BROBLEM THAT I HAVE A FIELD FOR PRIMERY KEY
WHICH IS AUTO GENERATED. I NEED THAT WHEN THE FORM IS LOADED THE NEXT AUTO
GENERATED NO SHOULD BE IN THE REQUIRED TEXTBOX. HOW TO GET THE NEXT NUMBER
FROM SQLSERVER2000 TO TEXTBOX.
 
auto-gen'd number for the primary key, use RETURN @@SCOPE_IDENTITY at the

I think when calling SCOPE_IDENTITY, you do not use the @@ on the front of
it. I was working with this yesterday and discovered that when return
SCOPE_IDENTITY you do it without the @@ in the front.
 
Chris,

You are absolutely right. It would be SCOPE_IDENTITY() or you can use
@@IDENTITY if scope is of no concern. Sometimes my brains mixes my
thoughts. :)

Aiax
 
Back
Top