Queries and Data Grids
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller
Queries and Data Grids
I have been trying to get to grips with the LiveCode and databases and I'm getting there, slowly... I can get connected, add data and select it. However, I am struggling to display the data nicely.
Whilst viewing this: http://lessons.livecode.com/m/4071/l/70 ... l-database
I was under the impression a datagrid is the best way forward, however I cannot seem to be able to get them working. If someone could explain to me how to set up the data grid columns and get the data from the query into the columns, it would be much appreciated.
Thanks guys.
Whilst viewing this: http://lessons.livecode.com/m/4071/l/70 ... l-database
I was under the impression a datagrid is the best way forward, however I cannot seem to be able to get them working. If someone could explain to me how to set up the data grid columns and get the data from the query into the columns, it would be much appreciated.
Thanks guys.
Re: Queries and Data Grids
Hi Mr. Smith,
OK, lets start with an easy example.
You have a database with 3 db fields
1. name
2. address
3. phone
When you execute this in Livecode:
select * from your_table
you get a TAB and CR delimited (text) list like:
name1 TAB address1 TAB phone1name2 TAB address2 TAB phone2
etc...
OK, so far?
Now you need to set up a datagrid of type TABLE*** with 3 columns in the same order as the fields in the database:
1. name
2. address
3. phone
*** This type only supports ONE Line data per column, if you have db fields that contain more than 1 line, the display will get messed up!
However type FORM is a BIT more complicated, see below
Then you can simply put the result of your query into the datagrid like:
Et voila, nicely displayed records in a datagrid.
Hope this gets you started!
Load the complete Datagrid docs in PDF here: http://lessons.livecode.com/m/datagrid
and work through it a couple of times, Datagrid are higly complex beasts, to say the least.
Best
Klaus
OK, lets start with an easy example.
You have a database with 3 db fields
1. name
2. address
3. phone
When you execute this in Livecode:
select * from your_table
you get a TAB and CR delimited (text) list like:
name1 TAB address1 TAB phone1name2 TAB address2 TAB phone2
etc...
OK, so far?
Now you need to set up a datagrid of type TABLE*** with 3 columns in the same order as the fields in the database:
1. name
2. address
3. phone
*** This type only supports ONE Line data per column, if you have db fields that contain more than 1 line, the display will get messed up!
However type FORM is a BIT more complicated, see below
Then you can simply put the result of your query into the datagrid like:
Code: Select all
...
put "seelect * from your_table" into tSQL
put revDataFromQuery(tab, return, tConnectionId, tSQL) into tDBResult
## Error checking:
if tDBResult begins with "revdberr" then
answer "error!"
exit to top
end if
## Success, now "fill datagrid with data:
set the DGTEXT of grp "your datagrid name here" to tDBResult
...
Hope this gets you started!
Load the complete Datagrid docs in PDF here: http://lessons.livecode.com/m/datagrid
and work through it a couple of times, Datagrid are higly complex beasts, to say the least.
Best
Klaus
Re: Queries and Data Grids
Hi Klaus,
Thanks for replying. Do I have to set the different columns in the datagrid before hand? I can't seem to find where I can do that.
Thanks for replying. Do I have to set the different columns in the datagrid before hand? I can't seem to find where I can do that.
Re: Queries and Data Grids
Okay that worked. Its just that the query data columns in the grid are labelled "Col 1" "Col 2" etc, is there a way to change that to the field names ?
-
- Posts: 746
- Joined: Sun Feb 04, 2007 11:01 pm
- Location: McKenna, WA
Re: Queries and Data Grids
smith8867,
If you're running LC 6 or 7 the columns are managed in the DG property inspector. LC 8 doesn't have this yet.
If you're running LC 6 or 7 the columns are managed in the DG property inspector. LC 8 doesn't have this yet.
Tom
MacBook Pro OS Mojave 10.14
MacBook Pro OS Mojave 10.14
Re: Queries and Data Grids
Yea I have LiveCode 8, that'll be why then. Thanks.quailcreek wrote:smith8867,
If you're running LC 6 or 7 the columns are managed in the DG property inspector. LC 8 doesn't have this yet.