Board index » delphi » "Execute" in ADO

"Execute" in ADO

I am trying to get back the return value from the stored procedure. Below is
the code I am using:

   cmd := CoCommand.Create; cmd.CommandType := adCmdStoredProc;
   cmd.CommandText := 'procTest';

   p := CoParameter.Create;
   p.Name := '@pTitle';  p.Type_ := adBStr;  p.Direction := adParamInput;
p.Value := 'TestTitle';
   cmd.Parameters.Append (p);

   p1 := CoParameter.Create;  p1.Name := '@newid';   p1.Type_ := adInteger;
   p1.Direction := adParamOutput;   p1.value := -1;
   cmd.Parameters.Append (p1);

   cmd.Set_ActiveConnection (m_Connection);
   cmd.Execute (t,EmptyParam, adOptionUnspecified); // t is just dummy
OleVar.
   result := cmd.Parameters.Get_Item (1).Value;         // !! This always
produces 0.

    The stored procedure is:
    CREATE PROCEDURE procAddTest
       @pTitle varchar(50),
       @newid int OUTPUT
        AS
            exec procGetNewId 'tbl1', @newid OUTPUT
            insert into tblPortfolio values (1, @newid, @pTitle)
            return @newid

When I am executing the query in Sql window I am getting back @newid
successfully.

Any help in this matter is greatly appreciated.

Michael

 

Re:"Execute" in ADO


Try adExecuteNoRecords instead of adOptionsUnspecified.
have fun
--
Binh Ly
http://www.castle.net/~bly/Programming/Delphi

Quote
Michael Blinchevsky <m...@rqsi.com> wrote in message

news:7o4m9p$k0t25@forums.borland.com...
Quote
> I am trying to get back the return value from the stored procedure. Below
is
> the code I am using:

>    cmd := CoCommand.Create; cmd.CommandType := adCmdStoredProc;
>    cmd.CommandText := 'procTest';

>    p := CoParameter.Create;
>    p.Name := '@pTitle';  p.Type_ := adBStr;  p.Direction := adParamInput;
> p.Value := 'TestTitle';
>    cmd.Parameters.Append (p);

>    p1 := CoParameter.Create;  p1.Name := '@newid';   p1.Type_ :=
adInteger;
>    p1.Direction := adParamOutput;   p1.value := -1;
>    cmd.Parameters.Append (p1);

>    cmd.Set_ActiveConnection (m_Connection);
>    cmd.Execute (t,EmptyParam, adOptionUnspecified); // t is just dummy
> OleVar.
>    result := cmd.Parameters.Get_Item (1).Value;         // !! This always
> produces 0.

>     The stored procedure is:
>     CREATE PROCEDURE procAddTest
>        @pTitle varchar(50),
>        @newid int OUTPUT
>         AS
>             exec procGetNewId 'tbl1', @newid OUTPUT
>             insert into tblPortfolio values (1, @newid, @pTitle)
>             return @newid

> When I am executing the query in Sql window I am getting back @newid
> successfully.

> Any help in this matter is greatly appreciated.

> Michael

Re:"Execute" in ADO


or In StoredProc, insert

SET NOCOUNT ON

at next AS keyword

Binh Ly <b...@castle.net>(?) ??? ?T????|
news:7o5a48$kov8@forums.borland.com?? ????????.

Quote
> Try adExecuteNoRecords instead of adOptionsUnspecified.
> have fun
> --
> Binh Ly
> http://www.castle.net/~bly/Programming/Delphi

> Michael Blinchevsky <m...@rqsi.com> wrote in message
> news:7o4m9p$k0t25@forums.borland.com...
> > I am trying to get back the return value from the stored procedure.
Below
> is
> > the code I am using:

> >    cmd := CoCommand.Create; cmd.CommandType := adCmdStoredProc;
> >    cmd.CommandText := 'procTest';

> >    p := CoParameter.Create;
> >    p.Name := '@pTitle';  p.Type_ := adBStr;  p.Direction :=
adParamInput;
> > p.Value := 'TestTitle';
> >    cmd.Parameters.Append (p);

> >    p1 := CoParameter.Create;  p1.Name := '@newid';   p1.Type_ :=
> adInteger;
> >    p1.Direction := adParamOutput;   p1.value := -1;
> >    cmd.Parameters.Append (p1);

> >    cmd.Set_ActiveConnection (m_Connection);
> >    cmd.Execute (t,EmptyParam, adOptionUnspecified); // t is just dummy
> > OleVar.
> >    result := cmd.Parameters.Get_Item (1).Value;         // !! This
always
> > produces 0.

> >     The stored procedure is:
> >     CREATE PROCEDURE procAddTest
> >        @pTitle varchar(50),
> >        @newid int OUTPUT
> >         AS
> >             exec procGetNewId 'tbl1', @newid OUTPUT
> >             insert into tblPortfolio values (1, @newid, @pTitle)
> >             return @newid

> > When I am executing the query in Sql window I am getting back @newid
> > successfully.

> > Any help in this matter is greatly appreciated.

> > Michael

Other Threads