DBExpress - returning value from TSQLStoredProc

I set up a test as basic as possible and get the same problem, returning
value of 0 from a SQLStoredProc.

I did the following test:

1) Placed TSQLConnection on form
2) Placed TSQLStoredProc on form and connected it to SQLConnection and
identified the storedprocname
3) Procedure is (in MSSQL Server 2000):
      INSERT REQHEAD (RequestNo) values (@requestno)
      RETURN @@identity
(tried above with @id = @@identity as well as OUTPUT parameter)

4) Put button on form with code attached:
var v_id, v_id2 : integer;
      sqlstoredproc1.parambyname('@requestno').asstring := Edit1.text;
      v_id2 := sqlstoredproc1.parambyname('@RETURN_VALUE').asinteger;
     except on E:Edatabaseerror do
5) Tried same above with @id OUTPUT parameter as well

Both tests yield 0. Any ideas?
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.


You may try something like:

v_id2 := sqlstoredproc1.Params.Items[sqlstoredproc1.Params.Count - 1].asinteger;

because the result will become the last parameter (I hope).

Alternatively you can always get that value using a separate query in the terms of the same session ('select @@IDENTITY as Ident'), open it and get the value.

Regards, Geo
it's just the opposite return value (from RETURN statement in stored procedure) is always number 0 parameter

    ADOCmd: TADOCommand;
  with ADOCmd do
    CommandText := 'NowyDokument';
    Parameters.ParamByName('@symbol').Value := symbol;
    Prepared := True;
    result := Parameters[0].Value;
DARRAHAuthor Commented:
Sorry, regardless, I'm still getting 0 back. I'd prefer not to have to do a separate query when the stored proc should be able to return the value. I hate to think I'm doing something obviously wrong, and not picking up on that. But as I setup the simplest test, I don't see anything.

Any other ideas or tests?
DARRAHAuthor Commented:
I tried move to dbexpsda.dll (Core Lab) and the problem is eliminated.
Closed, 250 points refunded.

Community Support Moderator
Experts Exchange

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
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

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.