Hello,

First of all You must know that I'm kind of new to Delphi.
Background:
I need to write an app that reads and write data from/in MSSQL, and do
this with stored procedures.

My problem: I have made a form on witch I put:
SQLConnection1: TSQLConnection;
//Societate= Company name
//StorePorc: GEN_ZoomSocietati      ;  no parameter required, return
data in dsSoc
dsSocietate: TDataSource;
sdsSocietate: TSQLDataSet;
cblSocietate: TDBComboBox;

//Locatie = Location
//StorePorc: GEN_ZoomDimensiuni     ;  no parameter required, return
data in dsLoc
dsLocatie: TDataSource;
sdsLocatie: TSQLDataSet;
cblLocatie: TDBComboBox;

// Gest =
//StorePorc: THG_GetGestiune         ; parameter: idlocatie
// return a list of things that are linked by Location by the
idlocation field
dsGest: TDataSource;
sdsGest: TSQLDataSet;
cblGest: TDBComboBox;


I can execute the StoredProc that are without any params, and get the
date, and populate the combos like this:
   dsSocietate.DataSet.First;
   while not dsSocietate.DataSet.Eof do
     begin
       ss:= ToString(dsSocietate.DataSet.FieldValues['societate']);
       cblSocietate.Items.Add(ss);
       dsSocietate.DataSet.Next;
     end;

  dsLocatie.DataSet.First;
   while not dsLocatie.DataSet.Eof do
     begin
       ss:= ToString(dsLocatie.DataSet.FieldValues['denumire']);
       cblLocatie.Items.Add(ss);
       dsLocatie.DataSet.Next;
     end;

Here is my THG_GetGestiune StoreProc
CREATE PROCEDURE THG_GetGestiune
       @idlocatie      INT     = NULL
AS
SET NOCOUNT ON
SELECT g.codgestiune, g.denumire, g.descarcare, g.codpersoana,
g.codgestionar
FROM thg_locatii_gestiuni lg
       INNER JOIN gestiuni g ON lg.codgestiune = g.codgestiune
WHERE lg.idlocatie = @idlocatie
SET NOCOUNT OFF


THE QUESTION:
How can I pass a parameter to this stored procedure?
I have tried with:
 sdsGest.CommandType := ctStoredProc;
 sdsGest.CommandText := 'THG_GetGestiune';
 sdsGest.ParamByName('@idlocatie').Value := 9;
 sdsGest.ExecSQL;
and aplication crash with message "List out of bounds(0)"

Please help,
Tanks in advance


Reply via email to