getting returned value from stored procedure
From: Bill (wwvanselow_at_truecommerce.com)
Date: 10/08/03
- Next message: jason: "Which is faster??"
- Previous message: Viatcheslav V. Vassiliev: "Re: Access violation when instancio query in debug time"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Wed, 8 Oct 2003 10:29:14 -0500
I'm using Delphi 5, and Microsoft ActiveX Data Objects 2.1 Library Version:
2.1
I'm using Command to try to get the returned values of a stored procedure
from a SQLServer DB. How do I set the returned value as a recordset? Here
is my code that I've tried. Is there a easier way for me to do this?
(I'm having trouble, because 2.1 does not have "adExecuteRecord" as a const
for the execute option)
stored procedure...
create procedure sptc_get_unique_id
as
declare @id bigint
set @id = isnull((select top 1 NEXTID from TC_UNIQUE_ID),1)
if exists (select top 1 NEXTID from TC_UNIQUE_ID)
update TC_UNIQUE_ID set NEXTID = @id + 1
else
insert into TC_UNIQUE_ID (NEXTID) values (@id + 1)
return @id
Delphi code...
var
Com: Command;
Res: Recordset;
Conn:Connection;
records, Param : OleVariant;
try
try
{ create the ADO connection, based on application config settings }
try
OleCheck(CoCreateInstance(CLASS_Connection, nil, CLSCTX_ALL,
IID__Connection, Conn));
Conn.Open(sConnection, sUserName, sPassword, 0);
except
on E:Exception do
raise Exception.Create('An error occured while connecting to the
database. Please make sure the database is available and the connection
setting is set up properly.');
end;
{ create an ADO result set and run the SQL query }
OleCheck(CoCreateInstance(CLASS_Recordset, nil, CLSCTX_ALL,
IID__Recordset, Res));
OleCheck(CoCreateInstance(CLASS_Command, nil, CLSCTX_ALL,
IID__Command, Com));
Com.Set_ActiveConnection(Conn);
Com.CommandType := adCmdStoredProc;
Com.CommandText := 'SPTC_GET_UNIQUE_ID';
Records :=Unassigned;
Param := EmptyParam;
Res := Com.Execute(records,Param,0)
Result := Res;
except
on E:Exception do
begin
Res:=nil;
raise;
end;
end;
finally
Conn:=nil;
if Res <> nil then
ADOCloseQuery(Res);
end;
- Next message: jason: "Which is faster??"
- Previous message: Viatcheslav V. Vassiliev: "Re: Access violation when instancio query in debug time"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|