By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,475 Members | 954 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,475 IT Pros & Developers. It's quick & easy.

RETIRIVAL OF AUTO GENERATED NUMBER

P: n/a
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
Nov 20 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
Cor
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/de...datareader.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.
I WILL APPRICIAT YOUR COOPERATION.

Nov 20 '05 #2

P: n/a
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" <MU**********@YAHOO.COM> wrote in message
news:2E**********************************@microsof t.com...
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

Nov 20 '05 #3

P: n/a
On Wed, 14 Jan 2004 07:17:08 -0600, aiax wrote:
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

To send me an E-mail, remove the underscores and lunchmeat from my E-Mail
address.
Nov 20 '05 #4

P: n/a
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

"Chris Dunaway" <dunawayc@_lunchmeat_sbcglobal.net> wrote in message
news:1g******************************@40tude.net.. .
On Wed, 14 Jan 2004 07:17:08 -0600, aiax wrote:
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

To send me an E-mail, remove the underscores and lunchmeat from my E-Mail
address.

Nov 20 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.