2016년 12월 16일 금요일

Fill labels with a query from Mysql database


Using this Mysql tutorial i can read and write from my mysql database.

I've a problem.

I can read all the fields of a row of a database and put them in a single lable using the "code" in attachment

I want that when i click on Btnview i can see the Field Nome in Name.Text lable Field Cognome in Surname.Text lable and so on..

Is it possible? and can you give me an example or some suggestion how to do that?

I attach also the structure of my db 

db.png 표시 중

structure.png 표시 중

-- 
In the for each sublist in list2 section,
put a series of blocks like
set label1.Text to select item 1 from sublist
set label2.Text to select item 2 from sublist
...

(adjust label names to taste).

-- 
i don't know how to reproduce what you suggested me (sorry) 

i post the screen 
test.png 표시 중
-- 
See 
➠ the many examples in the Web Services section  
for how to pick out pieces of text from a Web query response.

-- 
searching in your link but cannot find.

Can you give me a more specific link or give me snipset of example?

-- 
First post an image of the Web response text that is being parsed.

-- 
don't know if i'm answering to your question :)
PARSE.png 표시 중

-- 
You did not answer the question.
The response from the Web can't be parsed properly with out sample data directly 
copied into a global variable from the responseContent  in the Web1.GotText event.

Not from some muddied field too far downstream.

-- 
i think now i've solved.

see attachment image. With DO IT from ai2 seems ok the value
ok.png 표시 중

-- 
Works fine if i use only 8 rows of the database!

if i use more then 8 i recieve the error as in screenshot

Screenshot_.jpg 표시 중

ffff.png 표시 중

-- 
Insufficient information to debug.
Show the Web response text before parsing .

--
Select list item: Attempt to get item number 9 of a list of length 8: (2 8053921 name surname SI SI SI SI)
Note: You will not see another error reported for 5 seconds.


in attachment aia file

-- 

Select list item: Attempt to get item number 9 of a list of length 8: (2 8053921 name surname SI SI SI SI)
Note: You will not see another error reported for 5 seconds.


You took a long walk on a short pier.

Your table only has 8 columns, but you tried to select past the 8th and last element of the list that came back from a SELECT.

Either get a table with 12 columns or test your list length before stepping off the end.

-- 
No the table has more than 8 columns.

And this is the reason why i cannot understand the error!

--

learn how to debug your blocks... in App Inventor just use Do it, see also tip 4 here
-- 
Every data base system has a facility to dump its contents, in some readable form.

Post a dump of your data base here.

Investigation requires data.

-- 
i found that if the field is empty i recieve the error while if i put a charachter in each field (for example a - or whatever ) i can read all data and don't recieve any error!

Why if the field is empty i have error?

-- 
The answer to your question lies in how the incoming message in the Web1 responseContent looks, before you
grind it up with csv conversion.

You haven't shown us that.

Many database systems have a field-level DEFAULT value option, where a column in a table will always have a user-specified default value assigned instead of a NULL value.
That might let you work around the problem.
You might have to go back and clean up the rows with the empty fields,
or patch the upstream program feeding the data base to insert user-defined app-specific defaults 

-- 
For a quick easy experiment, try SELECTing a 13 column as a literal number, for example
SELECT F1,F2,....,F11,F12,1 FROM tablename
Then run it thru csv conversion, and count the length of the list.

Adding a 13th field (the "1") to the result might force the dbms to supply commas for the missing fields, to get the 13th value in the right slot.

-- 
So i've to do a select with real names of columns of database, for example
Select name, surname, g1, g2, etc and at the end ,1 from elencocuriosi ?

I'll try and let you know

--

See attached Do It.

csv_wierdness.PNG 표시 중


-- 

The stranger thing is that now i've filled all empty-strings with a "-" but i recieve the same error!!

Becoming crazy :D


-- 

now i've filled all empty-strings with a "-" but i recieve the same error!!

Do the dump again, and look for old records you missed, that are still short from before.

-- 
You were right! :)


-- 

댓글 없음:

댓글 쓰기