Board index » delphi » Get a RecordSet from a Store Procedure !

Get a RecordSet from a Store Procedure !

Hi everybody,

I solved the previous problem consulting the Microsoft Sql Server manual.
Now, i have another problem.
In which way could i get a recordset from a store procedure ?
I tryed to find a datatype that could hold the recordset of my store
procedure, but seems that this datatype does not exist.
Any suggestion ?
Cheers.

 

Re:Get a RecordSet from a Store Procedure !


The stored procedure does return a dataset!  Example

-- sp begin
CREATE PROCEDURE test AS
select * from customers
-- sp end

This is a simple SP that returns all the customers in our table.

From Delphi use a TQuery or a TStoredProc:

TQuery:

query.SQL.Add ('test');
query.Open
while not query.EOF do
begin
  showmessage (query.fieldbyname ('customername').asstring);
  query.next;
end

or assign a datasource and a dbgrid to the query.

TStoredProc:

storedproc.StoredProcName := 'dbo.test';
storedproc.Open
while not storedproc.EOF do
begin
  showmessage (storedproc.fieldbyname ('customername').asstring);
  storedproc.next;
end

Hope this helps!

--
Jacob Pedersen
AK Techotel
J.Peder...@techotel.dk

sgall...@altevie.com (Stefano Gallina) wrote in <3948a1ae@dnews>:

Quote
>Hi everybody,

>I solved the previous problem consulting the Microsoft Sql Server manual.
>Now, i have another problem.
>In which way could i get a recordset from a store procedure ?
>I tryed to find a datatype that could hold the recordset of my store
>procedure, but seems that this datatype does not exist.
>Any suggestion ?
>Cheers.

Re:Get a RecordSet from a Store Procedure !


Hi, Jacob,

Can you present those data using TDBGrid automatically or
programmatically? I tried but not successful.
Thanks in advance.

Regards,

Liping Gao

Quote
Jacob Pedersen wrote:

> The stored procedure does return a dataset!  Example

> -- sp begin
> CREATE PROCEDURE test AS
> select * from customers
> -- sp end

> This is a simple SP that returns all the customers in our table.

> From Delphi use a TQuery or a TStoredProc:

> TQuery:

> query.SQL.Add ('test');
> query.Open
> while not query.EOF do
> begin
>   showmessage (query.fieldbyname ('customername').asstring);
>   query.next;
> end

> or assign a datasource and a dbgrid to the query.

> TStoredProc:

> storedproc.StoredProcName := 'dbo.test';
> storedproc.Open
> while not storedproc.EOF do
> begin
>   showmessage (storedproc.fieldbyname ('customername').asstring);
>   storedproc.next;
> end

> Hope this helps!

> --
> Jacob Pedersen
> AK Techotel
> J.Peder...@techotel.dk

> sgall...@altevie.com (Stefano Gallina) wrote in <3948a1ae@dnews>:

> >Hi everybody,

> >I solved the previous problem consulting the Microsoft Sql Server manual.
> >Now, i have another problem.
> >In which way could i get a recordset from a store procedure ?
> >I tryed to find a datatype that could hold the recordset of my store
> >procedure, but seems that this datatype does not exist.
> >Any suggestion ?
> >Cheers.

Re:Get a RecordSet from a Store Procedure !


l...@pelmorex.com (Liping Gao) wrote in <3958F970.D877C...@pelmorex.com>:

Quote
>Hi, Jacob,

>Can you present those data using TDBGrid automatically or
>programmatically? I tried but not successful.
>Thanks in advance.

>Regards,

>Liping Gao

Quite easy...

Place a datasource on your form and a dbgrid. Then assign the following
properties in the object inspector...

datasource1.dataset := storedproc;
dbgrid1.datasource := datasource1;

--
Jacob Pedersen
AK Techotel
J.Peder...@techotel.dk

Other Threads