1 (edited by meideprac-x 2016-08-11 12:52:55)

Topic: ROWID in a TableGrid - SOLVED

Hi!

How could I show de row id in a tablegrid load from a database with    principal.TableGrid.dbSQL  ???

                      principal.TableGrid.sbSQL := 'SELECT rowid, name, phone  FROM database';        >>>>> doesn't work sad

Thanks !!!

Re: ROWID in a TableGrid - SOLVED

principal.TableGrid.sbSQL := 'SELECT id, name, phone  FROM database';   //should do the trick

Re: ROWID in a TableGrid - SOLVED

tcoton wrote:

principal.TableGrid.sbSQL := 'SELECT id, name, phone  FROM database';   //should do the trick

Thanks but id shows the id of the record. if I deleted records before use the statemen the number shown is not correlative , and I'm looking for a autoincrement column only shown in the tablegrid.

4 (edited by mathmathou 2016-08-07 08:36:28)

Re: ROWID in a TableGrid - SOLVED

Hello meideprac-x,


If your are talking about rowid as in "unique number referencing a record in a database", if you delete records, numbering is not continuous anymore, there is nothing you can do without a lot of coding to change that.


But if you are talking about rowid as in "number of the row in the tablegrid", even if you have deleted records, there is a way to display a column in your tablegrid with continuous numbering.


In the set-up of your tablegrid (or search button) just had the "# (Auto Increment)" found at the very bottom of the field selection window and you'll get a colum displaying a continuous numbering. If you put it side by side with the "record id" and you have deleted some records, you'll see the difference.


Hope this helps.


Cheers


Mathias

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

Zaza Gabor

5 (edited by meideprac-x 2016-08-07 20:10:26)

Re: ROWID in a TableGrid - SOLVED

mathmathou wrote:

But if you are talking about rowid as in "number of the row in the tablegrid", even if you have deleted records, there is a way to display a column in your tablegrid with continuous numbering.


In the set-up of your tablegrid (or search button) just had the "# (Auto Increment)" found at the very bottom of the field selection window and you'll get a colum displaying a continuous numbering. If you put it side by side with the "record id" and you have deleted some records, you'll see the difference.


Hope this helps.


Cheers


Mathias

Hi Mathias! Thanks. That's I want to do, but with a script. Could you help me please?

Re: ROWID in a TableGrid - SOLVED

meideprac-x
Can you more explain, what exactly you want to do?

Dmitry.

Re: ROWID in a TableGrid - SOLVED

DriveSoft wrote:

meideprac-x
Can you more explain, what exactly you want to do?

Hi Dimitry!
I have a table with an ID column that has no correlative number (because I deleted rows above) and I want to present it in a tableGrid whose field ID must have correlative number. That is so easy with the Object Inspector > properties > settings > select #Auto Increment like explain Mathias, but I use this tablegrid to display different data according to different search criteria I and dump the data using script (principal.TableGrid.sbSQL := 'SELECT id, name, phone  FROM database'), without using the Object Inspector.
How could I add a column in this tablegrid wich was Auto Increase within script?
I hope I explained well, excuse my bad English
Thanks!
Javi

Re: ROWID in a TableGrid - SOLVED

meideprac-x
Check out this example:

procedure Form1_bScript_OnClick (Sender: string; var Cancel: boolean);
begin
    Form1.GridEmployees.dbSQL:='SELECT id, "$autoinc", 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.

9 (edited by meideprac-x 2016-08-11 12:55:29)

Re: ROWID in a TableGrid - SOLVED

DriveSoft wrote:

meideprac-x
Check out this example:

procedure Form1_bScript_OnClick (Sender: string; var Cancel: boolean);
begin
    Form1.GridEmployees.dbSQL:='SELECT id, "$autoinc", 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;

Thanks Dimitry, "$autoinc" is the solution. It's what I was looking for big_smile