|
List Info
Thread: dbExpress , MSSQL stored procedure params error
|
|
| dbExpress , MSSQL stored procedure
params error |
  United States |
2007-02-07 21:08:03 |
|
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
__._,_.___
.
__,_._,___
|
| Re: dbExpress , MSSQL stored procedure
params error |
  United States |
2007-02-08 02:21:38 |
|
Salut Bogdane,
Problema ta cred ca consta in a lega doua tabele, una tip master locatii si una details gestiuni. Defineste locatiile intr-o structura de genul:
id locatie
denumire locatie
etc, asta ar trebui sa fie structura tabelei master
si tabela detail in structura:
id locatie
id gestiune
denumire gestiune
etc
Pentru fiecare tabela defineste o cheie primara din id_locatie pentru tabela master si id_locatie+denumire gestiune pentru tabela detail.
In proprietatile tabelei detail la master detail selecteaza tabela de locatii si la cimpurile de legatura id_locatie din tabela master si id_locatie din tabela detail( uzual se numeste si child)
In forma pune un control de tip TDBGrid cu sursa tabela master(locatii) si inca un control de acelasi tip cu sursa detail(gestiuni). Executa un open pe ambele tabele si in grid-ul master vei avea locatiile, iar in gridul detail vei avea gestiunile locatiei respective.
Pentru a cauta o locatie anume, introdu un cimp edit in forma si un buton cu caption Cautare. introduci in TEdit control locatia de cautare si peonclick-ul butonului de cautare exexuti instructiunea
dmmodule.dataset.tablename.LOCATE('ID_LOCATIE', [TEditcontrol.text], ''); instructiune care iti pozitioneaza cursorul pe inregistrarea dorita daca o gaseste dupa continutul TEdit control sau iti returneaza FALSE daca nu o gaseste.
Scapi in felul acesta de procedurile stocate pentru actiuni uzuale.
Oricum la definirea unei proceduri stocate ai niste proprietati care definesc parametrii de apel si parametrii de retur, le definesti natura si valoarea implicita, ii initializezi cu proprietatea parambyname si apelezi procedura stocata.
Procedura stocata trebuie sa aibe in descriere parametrii apelanti si parametrii de retur. In Oracle exista ceva de genul CREATE "PROCEDURA" Inputvalue ..... output value corp procedura
Asa cum ai definit tu procedura respectiva, variabila ta nume variabila este considerata o variabila locala si nu este returnata ca rezultat.
Daca vrei mai multe detalii ma poti contacta aici pe adresa armitage49%40yahoo.com">armitage49 yahoo.com, sau pe adresa mea personala armitage%40rdslink.ro">armitage rdslink.ro sau pe yahoo mess id armitage49
cu stima
Adrian POPA
Fie ca programarea sa iti lumineze viata, sa iti bucure ochiul ziua precum femeia noaptea (tare nu ?, am copiat-o dintr-un alt mail al unui programator)
bogdan_pricop < bogdan_pricop%40yahoo.com">bogdan_pricop yahoo.com> wrote:
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
---------------------------------
Be a PS3 game guru.
Get your game face on with the latest PS3 news and previews at Yahoo! Games.
[Non-text portions of this message have been removed]
__._,_.___
.
__,_._,___
|
| Re: dbExpress , MSSQL stored procedure
params error |
  United States |
2007-02-08 02:37:52 |
|
Am reciti mail tau si am mai gasit o observatie:
Selectul pe care l-ai introdus nu iti intoarce un singur rezultat ci un subset de rezultate, poate avea o touple sau mai multe. Pentru a rezolva acest lucrumai poti face urmatiorul lucru:
Creaza un cursor in mysql care sa returneze toate inregistrarile din gestiuni pentru locatia introdusa ca parametru :
create view aaaa select * from gestiuni a where a.id_locatie = :numar de locatie dorit
definesti un tsqldataset pentru acest view
si cind citesti din forma un id de locatie il transmiti ca parametru view-ului pe care in apelezi cu o instructiune de genul select * from aaaa si iti returneaza tot setul chiar daca contine ouna sau mai multe rezultate.
selectul folosit de tine iti intoarce o tabelea in care ai atasate cimpurile din locatii si gestiunile aferente in urmatoatarea forma:
locatia 1 gestiuea 1
locatia 1 gestiunea 3
locatia 1 gestiune 10
locatia 2 gestiunea 2
locatia 2 gestiunea 4
etc si nu cred ca asta este rezultatul pe care il doresti
daca ai putina rabdare pe sfirsitul asta saptamina, dupa ce imi instalez mysql-ul (sa imi comunici ce varianta ai pentru compatibilitate) o sa iti fac un demonstrativ mic la problema
ta si iti trimit si sursele aferente sa vezi cum merge, numai daca vrei.
Cu stima si respect pentru incepatori
Adrian POPA
PS. scuza-mi eventualele greseli de ortografie, nu imi corectez textul dupa ce il tastez
bogdan_pricop < bogdan_pricop%40yahoo.com">bogdan_pricop yahoo.com> wrote:
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
---------------------------------
Don't be flakey. Get Yahoo! Mail for Mobile and
always stay connected to friends.
[Non-text portions of this message have been removed]
__._,_.___
.
__,_._,___
|
[1-3]
|
|