Topic: Query to populate several textboxes from tablegrid
Hi all,
I need your assistance.
I would like to create a query to populate several textboxes based on the selected record from a table grid.
I tried for each textbox to write an SQLExecute query, which is working just fine, but I think there should be am easier way.
The structure of my table is:
tblRetete:
-id = integer
-id_tblTipReteta=integer FK
-Activ = boolean
-id_tblArticol = integer FK
-id_tblArticol1=integer FK
-Cantitate
tblArticol contains all the materials (Finished Goods, Row Material)
To select the records, I've created this Select statement, which populate a tablegrid and is working fine:
procedure cautaReteta (Sender: TObject; var Cancel: boolean); // cauta reteta
var
ca, na, cc, nc, nr , tr : String;
sr, cf: integer;
begin
ca:= TRIM(frmMain.txtCodArticolReteta.Text);
na:= trim(frmMain.txtNumeArticolReteta.Text);
cc:=TRIM(frmMain.txtCodComponentaReteta.Text);
nc:=TRIM(frmMain.txtNumeComponentaReteta.Text);
nr:=frmMain.txtNumeReteta.Text;
tr:=SQLExecute('SELECT TipReteta from tblTipReteta');
//sr:=frmMain.chkStatut.State := cbChecked;
frmMain.grdRetete.dbSQL:=('SELECT NumeReteta,NrTipReteta,CantRef,CASE Activ when 1 THEN "DA" when 0 THEN "NU" End ,a.CodArticol, a.NumeArticol, ' +
' CASE Comisionare when 1 then "DA" when 0 then "NU" End,c.CodArticol, c.NumeArticol, ' +
' Cantitate, CASE Fix when 1 then "DA" when 0 then "NU" End from tblRetete r' +
' INNER JOIN tblArticol a on r.id_tblArticol=a.id ' +
' INNER JOIN tblArticol c on r.id_tblArticol1=c.id ' +
' INNER JOIN tblTipReteta tr on r.id_tblTipReteta=tr.id ' +
' WHERE a.CodArticol like "%' + ca + '%"' +
' AND a.NumeArticol like "%' + na + '%"' +
' AND c.codArticol like "%' + cc + '%"' +
' AND c.NumeArticol like "%' + nc + '%"' +
' AND NumeReteta like "%' + nr + '%"');
frmMain.grdRetete.dbListFieldsNames:='Nume Reteta,Tip Reteta,Cant. Ref.,Activ?,Cod Articol, Nume Articol,Comisionare?,Cod Componenta, Nume Componenta, Cantitate, Fix?';
frmMain.grdRetete.dbSQLExecute;
end;
But now, I want to add the Query to edit / modify a selected record from the tablegrid.
Thank you.
Best regards,
Alin
Alin