Topic: TableGrid filled by query

Hello Dmitry and all MVD fans,


OK, I give up on that one. I've searched the forum and  the web but only found reference to embarcadero and other data-aware components, which I'm not looking for.


What I would like to know is : how do I fill a TableGrid with a query.


Simple query :

SELECT id, name, phone FROM customers;

Now, on Form1.TableGrid1...


How do I display the results, rows after rows in a TableGrid ?


I know we can use the embeded query engine in MVD and I do it a lot, but I would like to know how to do it manually smile


I am sure there is some count.row -1 involved and some for i=0 to count.rows do... but I have been unable to achieve something that works.


Cheers


Mathias

I'm a very good housekeeper !
Each time I get a divorce, I keep the house

Zaza Gabor

Re: TableGrid filled by query

procedure Form1_bScript_OnClick (Sender: string; var Cancel: boolean);
begin
    Form1.GridEmployees.dbSQL:='SELECT id, lastname, firstname, salary FROM employees'; // the id field, want to be able to edit or delete the entry from the table component
    Form1.GridEmployees.dbGeneralTable := 'employees'; // Optional (in the case of complex SQL queries with sub queries, you need to choose the main table of the database, also it need to be able to edit or delete the entry from the table component)
    Form1.GridEmployees.dbListFieldsNames :='delete_col,name2,name3,name4'; // If you do not want to see the value of the id in the component table, enter a name for the column delete_col
    Form1.GridEmployees.dbSQLExecute;
end;
Dmitry.

Re: TableGrid filled by query

I love this one, this is new smile

Form1.GridEmployees.dbListFieldsNames :='delete_col,name2,name3,name4'; // If you do not want to see the value