Return @@Identity to ADP Front End

Hello
I have an SP in SQL Server 2000 that returns an Identity.  I want to display the Identity to the user via a message box in my Access Data Project (ADP).
My SP looks like this:

Create Procedure uspMySp
@AssetName char (10), @AssetTown char (10)
AS
INSERT INTO tblMyTable
([Assetname], [AssetTown])
values
(@AssetName, @AssetTown)
return @@Identity

MyTable contains 3 fields (@AssetCode, @AssetName, @AssetTown)

How would you execute the SP and provide the user with the @@Identity via a message box?  I do not know how to use parameters...so if that is the way forward I could do with an example.

Many thanks, Simon
doddwellAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

flavoCommented:
Somethign like this:

    Dim cmd As ADODB.Command
   
    Set cmd = New ADODB.Command
   
    With cmd
        .ActiveConnection = CurrentProject.Connection
        .CommandType = adCmdStoredProc
        .CommandText = "uspMySp"
        .Parameters.Append .CreateParameter("@RETURN_VALUE", adInteger, adParamReturnValue)
        .Parameters.Append .CreateParameter("@AssetName", adChar, adParamInput, 10, "myValue") '// change myValue as req'd
        .Parameters.Append .CreateParameter("@AssetTown", adChar, adParamInput, 10, "myValue") '// change myValue as req'd
        .Execute
        MsgBox .Parameters("@RETURN_VALUE").Value
    End With

    Set cmd = Nothing
End Sub

Dave
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Aneesh RetnakaranDatabase AdministratorCommented:
Can you modify your sp like this

Create Procedure uspMySp
@AssetName char (10), @AssetTown char (10)
AS
SET NOCOUNT ON
INSERT INTO tblMyTable
([Assetname], [AssetTown])
values
(@AssetName, @AssetTown)
SELECT SCOPE_IDENTITY()

GO
0
doddwellAuthor Commented:
Flavo - that worked..thanks very much.
anneeshattingal - what does your mod do....please advise.
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

Aneesh RetnakaranDatabase AdministratorCommented:
I am not a front end expert, i knows only sql..

Create Procedure uspMySp
@AssetName char (10), @AssetTown char (10)
AS
SET NOCOUNT ON      /* this was missing in ur sp; If u dont put this, you will get the no.of rows affected along with the the return values */
INSERT INTO tblMyTable
([Assetname], [AssetTown])
values
(@AssetName, @AssetTown)
SELECT SCOPE_IDENTITY() /*Another good practice is to use SCOPE_IDENTITY() in leu of @@IDENTITY, refer BOL for detsils . Also it is better to return the values using either Output variable or using the select statements as i shown */

GO
0
doddwellAuthor Commented:
Thanks to you both of you for your help.  Most points to flavo for answering question directly...remainder to anneeshattingal for supplementary info.
0
Aneesh RetnakaranDatabase AdministratorCommented:
No probs for points.. But dont forget to follow the above rules while creating sps
0
doddwellAuthor Commented:
Thanks for that...have checked out your suggestions in BOL and looks like good practice...have applied it in this sp and will try and remember to do it in future.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SQL Server

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.