Topic: How To reverse Value AttachDB Table to Edit.text

How To edit script on Double click at TableGrid1 to display editor3.text, editor4.text, editor5.text
but database from attach database
help me please
https://i.imgsafe.org/10c1e6a79b.png

Post's attachments

Attachment icon Lesson Attach Database.zip 24.18 kb, 401 downloads since 2016-06-15 

My Visual Database : I Love You
Easy For Beginner Student For Me

Re: How To reverse Value AttachDB Table to Edit.text

Hello Prahousefamily

Why not use a SQL query to retrieve the values of a grid column ?

procedure frmApplication_Button1_OnDoublerClick (Sender: string; var Cancel: boolean);
begin
    frmApplication.NameUser.Text := SQLExecute('SELECT clientname FROM application WHERE id='+IntToStr(Form1.TableGrid1.dbItemID));
    frmApplication.PhoneUser.Text :=  SQLExecute('SELECT clientphone FROM application WHERE id='+IntToStr(Form1.TableGrid1.dbItemID));
end;

No matter if the column order of the grid is changed for any reason.
I do this way in my applications and I even add OnKeyUp and OnKeyDown event to navigate the grid and display the different values of a row of the grid.

Is this OK for you ?

JB

3 (edited by prahousefamily 2016-06-15 10:05:10)

Re: How To reverse Value AttachDB Table to Edit.text

Can not  use function

procedure frmApplication_Button1_OnDoublerClick (Sender: string; var Cancel: boolean);
begin
    frmApplication.NameUser.Text := SQLExecute('SELECT clientname FROM application WHERE id='+IntToStr(Form1.TableGrid1.dbItemID));
    frmApplication.PhoneUser.Text :=  SQLExecute('SELECT clientphone FROM application WHERE id='+IntToStr(Form1.TableGrid1.dbItemID));
end;

i try this SQLExecute not work
because data in table grid from attach database
in project attach database

//public var
var
AppPath: string;
attachdb: string;

procedure Form1_TableGrid1_OnCellClick (Sender: string; ACol, ARow: Integer);
begin
????????????????????????????????????????????????????????????????????????????
end;

procedure Form1_Button1_OnClick (Sender: string; var Cancel: boolean);
begin
Form1.TableGrid1.dbSQL:=
' SELECT person.firstname,person.lastname, '+
' person.record_count FROM lib.person '+
' WHERE person.firstname like "%'+Form1.Edit1.Text+'%" AND '+
' person.lastname like "%'+Form1.Edit2.Text+'%" ';
Form1.TableGrid1.dbSQLExecute;
end;

begin
AppPath := ExtractFilePath(Application.ExeName);
attachdb:= SQLExecute('ATTACH DATABASE ''lib.db'' as ''lib''');
end

.

how to fix ?

My Visual Database : I Love You
Easy For Beginner Student For Me

4 (edited by prahousefamily 2016-06-16 01:11:46)

Re: How To reverse Value AttachDB Table to Edit.text

OK  Work ! Now Fix Passed Thank You jean.brezhonek
I edit code in even Form1_TableGrid1_OnCellDoubleClick

procedure Form1_TableGrid1_OnCellDoubleClick (Sender: string; ACol, ARow: Integer);
var
libs: TDataSet;
irow :integer ;
begin
irow := Form1.TableGrid1.SelectedRow  ;
SQLQuery(
' SELECT person.firstname,person.lastname,'+
' person.record_count FROM lib.person where person.id ='+inttostr(Form1.TableGrid1.dbIndexToID(irow) )
, libs);
while not libs.Eof do
    begin
        Form1.Edit3.Text := libs.FieldByName('firstname').AsString;
        Form1.Edit4.Text := libs.FieldByName('lastname').AsString;
        Form1.Edit5.Text := libs.FieldByName('record_count').AsString;

        libs.Next;
    end;
        libs.Free;
end;

and add fileld "ID" in tablegrid1

procedure Form1_Button1_OnClick (Sender: string; var Cancel: boolean);
begin
Form1.TableGrid1.dbSQL:=
' SELECT person.firstname,person.lastname, '+
' person.record_count,person.id FROM lib.person '+
' WHERE person.firstname like "%'+Form1.Edit1.Text+'%" AND '+
' person.lastname like "%'+Form1.Edit2.Text+'%" ';
Form1.TableGrid1.dbSQLExecute;
end;

https://i.imgsafe.org/1fc8b502c4.png

My Visual Database : I Love You
Easy For Beginner Student For Me