Board index » delphi » Need examples of recordset from stored procedure with parameters

Need examples of recordset from stored procedure with parameters

I would be grateful for any examples (however simple)
that use Delphi to get a recordset back from an SQL
Server stored procedure that needs parameters passed
to it. I am having problems with this that I am sure I
can solve if I can just get hold of some working
examples.

Thanks in advance,
Kelly.

____________________________________________________________
Do You Yahoo!?
Get your free @yahoo.co.uk address at http://mail.yahoo.co.uk
or your free @yahoo.ie address at http://mail.yahoo.ie

--
Posted from web11803.mail.yahoo.com [216.136.172.157]
via Mailgate.ORG Server - http://www.Mailgate.ORG

 

Re:Need examples of recordset from stored procedure with parameters


CREATE PROCEDURE view_tar @n_pod integer
AS
 select id_tar,tar,n_pod,n_kat from dbo.tar where n_pod=@n_pod

In mssql query tool - exec view_tar 1 and we have in result window

id_tar      tar            n_pod       n_kat      
----------- -------------- ----------- -----------
1           6.59           1           1          
2           4.03           1           2          
3           0.00           1           3          
4           3.61           1           4          
5           0.00           1           5          
6           0.00           1           6          
7           0.00           1           7

in delphi  TForm, TStoreProc, TDataSource, TDBGrid
TStoreProc.StoredProcName=view_tar
TStoreProc.Paramets - one parameter - Name=@n_pod
                                      ParamType=ptInput
                                      Value=1
                                      Type=Integer
TstoredProc.Active=true and you will see results in grid.
Sorry but I cann't copy grid to the message so you must believe that it
shows exactly the same data. Good luck.

Quote
"=?iso-8859-1?q?Kelly-Anne=20Frendo?=" <kfre...@yahoo.com> wrote in message <news:20010821143927.47367.qmail@web11803.mail.yahoo.com>...
> I would be grateful for any examples (however simple)
> that use Delphi to get a recordset back from an SQL
> Server stored procedure that needs parameters passed
> to it. I am having problems with this that I am sure I
> can solve if I can just get hold of some working
> examples.

Re:Need examples of recordset from stored procedure with parameters


Hello, "Kelly-Anne Frendo" <kfre...@yahoo.com>! You wrote:

Quote
> I would be grateful for any examples (however simple)
> that use Delphi to get a recordset back from an SQL
> Server stored procedure that needs parameters passed
> to it. I am having problems with this that I am sure I
> can solve if I can just get hold of some working
> examples.

I can't understand what a trouble did you meet. There are all thing too
simple.
Do you use ADO? I will give some simple examples using ADO Delphi
components.

First at all you can use TADOStoredProc component. You can pass to it any
number of parameters and retrieve a recordset.
The following code snip is from my working project:

 with spMIDPotr do
  try
   DisableControls;
   Active := False;
   ProcedureName := 'GetPVOMTS_Report;1';
   Parameters.Refresh;
   Parameters.ParamByName('@DateStart').Value := fDateStart;
   Parameters.ParamByName('@Da{*word*249}d').Value := fDa{*word*249}d;
   Active := True;
  finally
   EnableControls;
  end;
end;
Here is spMIDPotr is TADOStoredProc component. It is linked to a DataSource
and outputs data to dbGrid.

Also it possible to use TADOQuery component. As SQL statement you can put
string like "EXEC StoredProcName :p1, :p2, ..." and define all the
parameters through Parameters property.

Good luck. I hope it will help.

--
    Evgeny V. Levashov, software developer,
    ICQ UIN 34864288
    Mebel Massiv Co, Tula, Russia
    http://home.tula.net/mebelmassiv

Other Threads