show returned data from query into fields

Creating desktop or client-server database solutions?

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

francof
Posts: 237
Joined: Fri Apr 11, 2014 10:51 am

show returned data from query into fields

Post by francof »

ciao all, first of all sorry for my rough english.
yes I now, I'm completely ignorant of databases. after long research about how put my data into fields on the card I resolved so:

(the db file is a .mdb, I open it in ODBC mode.)

below the query that return 3 fields of the table TBLDISTILLATI. the fields are: DESCRIZIONE, ZONAPROD, MATERIAPRIMA

Code: Select all

put "SELECT DESCRIZIONE, ZONAPROD, MATERIAPRIMA from TBLDISTILLATI WHERE DISTILLATO = '"& gSelezione &"' " into tSQL
then I show data:

Code: Select all

    set ItemDel to tab
    put item 1 of tRecords into field "fldDescr"
    put item 2 of tRecords into field "lblZonaProd"
    put item 3 of tRecords into field "lblMatPrima"


Hit I the nail on the head? or there is a better and formal way?

I come from Visual Basic where, in this case, I could refer directly to the names of the fields of the DB specified in the query.

thanks for your attention
franco
Klaus
Posts: 14324
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: show returned data from query into fields

Post by Klaus »

Buongiorno Franco,

yes, that is the way to go :D

You could use a repeat loop however like this:

Code: Select all

...
set ItemDel to TAB
put "fldDescr,lblZonaProd,lblMatPrima" into tFields
repeat with i = 1 to 3
    put item i of tRecords into fld (item i of tFields)
end repeat
...
Best

Klaus
francof
Posts: 237
Joined: Fri Apr 11, 2014 10:51 am

Re: show returned data from query into fields

Post by francof »

Gutenmorgen Klaus, grazie 1000! you solve my doubt.

I am glad that my attempt has proved to be accurate, at least in concept. certainly yours way it's more smart and efficient. so, I think that I will use it.
in case of a lot of data the populating loop is certainly to be preferred.

one more question: there is some tutorial or guide about databases management? (e.g. queries with variables, filling fields with returned data, ect.) all I found on LiveCode Lessons refers to very simple situations of limited use in the real world.

thanks again for your help
franco
Klaus
Posts: 14324
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: show returned data from query into fields

Post by Klaus »

francof wrote:one more question: there is some tutorial or guide about databases management? (e.g. queries with variables, filling fields with returned data, ect.)
all I found on LiveCode Lessons refers to very simple situations of limited use in the real world.
sorry, but I don't know.

Just ask here :D
francof
Posts: 237
Joined: Fri Apr 11, 2014 10:51 am

Re: show returned data from query into fields

Post by francof »

Hi again Klaus,
unfortunately I got this error
" card "crdDistillati": execution error at line 65 (Chunk: no such object), char 1 "

at line

Code: Select all

put item i of tRecords into fld (item i of tFields)
something is missing?

franco
Klaus
Posts: 14324
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: show returned data from query into fields

Post by Klaus »

Hi Fanco,

oops, yes, sorry, my fault, forgot the new itemdel! :oops:

Do this:

Code: Select all

...
set ItemDel to TAB
put "fldDescr,lblZonaProd,lblMatPrima" into tFields
replace COMMA with TAB in tFields
repeat with i = 1 to 3
    put item i of tRecords into fld (item i of tFields)
end repeat
...
Best

Klaus
francof
Posts: 237
Joined: Fri Apr 11, 2014 10:51 am

Re: show returned data from query into fields

Post by francof »

ciao Klaus,
don't be :oops:..... now it's working fine.if we ever meet, remember that, you got a free beer :)

franco
SparkOut
Posts: 2984
Joined: Sun Sep 23, 2007 4:58 pm

Re: show returned data from query into fields

Post by SparkOut »

If Klausimausi ever meets up with everyone who says that, he'd better take very good care of his liver!
Klaus
Posts: 14324
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: show returned data from query into fields

Post by Klaus »

SparkOut wrote:If Klausimausi ever meets up with everyone who says that, he'd better take very good care of his liver!
:D :D :D
francof
Posts: 237
Joined: Fri Apr 11, 2014 10:51 am

Re: show returned data from query into fields

Post by francof »

SparkOut wrote:If Klausimausi ever meets up with everyone who says that, he'd better take very good care of his liver!
ah ah! I just said "A" (one) beer, and anyway I'll make a sacrifice :D

ciao all
franco
SparkOut
Posts: 2984
Joined: Sun Sep 23, 2007 4:58 pm

Re: show returned data from query into fields

Post by SparkOut »

I meant there are a LOT of people who have said they will buy A beer for Klaus.
francof
Posts: 237
Joined: Fri Apr 11, 2014 10:51 am

Re: show returned data from query into fields

Post by francof »

SparkOut wrote:I meant there are a LOT of people who have said they will buy A beer for Klaus.
Hi SparkOut,
excuse me. now I understand, as I said my English is very bad.
AxWald
Posts: 578
Joined: Thu Mar 06, 2014 2:57 pm

Re: show returned data from query into fields

Post by AxWald »

Hi,
francof wrote:one more question: there is some tutorial or guide about databases management? (e.g. queries with variables, filling fields with returned data, ect.) all I found on LiveCode Lessons refers to very simple situations of limited use in the real world.
As you write in your first post you're working with a .mdb. So you might have MS Access at hand and can use its query builder.
Building complex queries using the design view (or even using the wizards) is quite easy, and then you switch view to SQL - and voilá, nice juicy SQL code to copy out ;-)

This is a very handy thing, and since Access can connect to nearly every database engine (via ODBC) you can prepare your SQL statements there at first, check the results, and then copy the tested code.
For sure, some DBs will need minor changes in the syntax, but that's nothing a good text editor cannot do for you ;-)

But it's priceless when the SQL statements grow longer, writing multi-line code with many parentheses and single/ double quotes, inserted variables, line breaks - without knowing beforehand if you used the correct join ...

If I remember correctly, Access comes with an example database (northwind.mdb) that is quite useful to learn the basics of using structured data in a relational environment ;-)
There's alternatives, but I have yet to find a tool that makes it such simple to create even the most esoteric queries.

For sure, if you don't have it already, Access is quite a bummer when it comes to buying it. For this, I'd look at EBay for the 2003 version, comes for quite small money often & is quite good (Careful, there's MS Office versions that doesn't include Access!).

Have fun!
All code published by me here was created with Community Editions of LC (thus is GPLv3).
If you use it in closed source projects, or for the Apple AppStore, or with XCode
you'll violate some license terms - read your relevant EULAs & Licenses!
francof
Posts: 237
Joined: Fri Apr 11, 2014 10:51 am

Re: show returned data from query into fields

Post by francof »

Hi AxWald,
thanks for your reply.
AxWald wrote: .....
But it's priceless when the SQL statements grow longer, writing multi-line code with many parentheses and single/ double quotes, inserted variables, line breaks - without knowing beforehand if you used the correct join ...
....
yes, this is half of the job.

although I do not use it too much i've the office 2007 version. curiously the query builder button it's always grayed out.
I tried to turn-on it unsuccessfully.

franco
AxWald
Posts: 578
Joined: Thu Mar 06, 2014 2:57 pm

Re: show returned data from query into fields

Post by AxWald »

Hiya!
francof wrote:[...] curiously the query builder button it's always grayed out.
I tried to turn-on it unsuccessfully.
Don't you get something like this?
The query builder in Access
The query builder in Access
Then you might have an Access Runtime version :/

(The upper part is where you can show tables, link them at your desire, designate the fields you want to use in your query, add critera, sorts, and can do calculations.
Then you test it, and if OK you switch view to the lower part: Nicely automagically created SQL code ;-) )

Have fun!
All code published by me here was created with Community Editions of LC (thus is GPLv3).
If you use it in closed source projects, or for the Apple AppStore, or with XCode
you'll violate some license terms - read your relevant EULAs & Licenses!
Post Reply