How matlab display data from database in gui edit box

Hi everyone, i programing license plate recognition programs, and appeared problem. So after few examples i figure out my code.
function pushbutton1_Callback(hObject, eventdata, handles)
conn = database('baze', 'root', 'root', 'Vendor', 'MYSQL', 'Server', 'localhost', 'PortNumber', 3306);
setdbprefs('datareturnformat','structure');
a = get(handles.edit8,'String');
if iscell(a) && numel(a) == 1
a = a{1};
end
if ~ischar(a) || isempty(a);
error('A valid string must be supplied!');
end
sqlquery = ['select vardas, pavarde, laipsnis, pareigos, telefonas, marke, numeris, tarnyba from info '...
'where numeris = ' '''' a ''''];
curs = exec(conn, sqlquery);
curs = fetch(curs);
curs.data
close(curs)
close(conn)
All this i got in Matlab command window, but if i have gui aplication and i want retrive value in gui wich have edit text box. Example: after i input car plate number - got 'vardas' in edit1 and 'pavarde' in edit2. Thanks in advance for the answers.

2 件のコメント

akshatha nayak
akshatha nayak 2019 年 4 月 29 日
How to display the database rows in GUI Or database multiple rows in GUI
Geoff Hayes
Geoff Hayes 2019 年 4 月 29 日
akshatha - I see that you have a question posted at https://www.mathworks.com/matlabcentral/answers/459147-how-to-display-the-database-in-gui-or-database-multiple-rows-in-gui. Please further the conversation there.

サインインしてコメントする。

 採用された回答

Geoff Hayes
Geoff Hayes 2016 年 10 月 2 日

0 投票

Gytis - if you want to retrieve the text from your edit1 and edit2 controls, then in the above pushbutton callback you would use the handles structure to get the values for these controls:
edit1Text = get(handles.edit1,'String');
edit2Text = get(handles.edit2,'String');
You can then use the above two local variables however you wish. Is this the solution that you are looking for?

8 件のコメント

Gytis Raudonius
Gytis Raudonius 2016 年 10 月 2 日
編集済み: Gytis Raudonius 2016 年 10 月 2 日
No sir i want to get text in my edit1 and edit2, as example sqlquery have vardas, and i want retrive answer in edit1. As you see "a" is equal edit8 this is car plate number, i write car plate number and after pushbutton callback i want retrive information in edit1 car driver name . I hope you understand what i want to say.
Geoff Hayes
Geoff Hayes 2016 年 10 月 3 日
Gytis - then use set to set the text of your edit1 and edit2 controls. For example, you could do
myString = 'Some text';
set(handles.edit2, 'String', myString);
Gytis Raudonius
Gytis Raudonius 2016 年 10 月 3 日
don't work then in 'Some text' i write 'vardas' from sqlquery, got error undefined variable 'vardas'
Geoff Hayes
Geoff Hayes 2016 年 10 月 3 日
Doesn't curs.data have the data that you have requested? You will need to extract the vardas data from here and then use that in your set.
Gytis Raudonius
Gytis Raudonius 2016 年 10 月 6 日
hm... so how i can extract 'vardas' from sqlquery?
Geoff Hayes
Geoff Hayes 2016 年 10 月 7 日
um...if curs.Data is a cell array with a single row and assuming that your query returns exactly one record, then I suspect that vardas would be the first field since it is the first element in your select statement. Maybe it would be
curs.Data{1}
I say maybe since I don't have the Database Toolbox and so can't verify. But the examples from fetch seem to suggest this.
Gytis Raudonius
Gytis Raudonius 2016 年 10 月 31 日
no it's not working error like Error using subsref Cell contents reference from a non-cell array object.
Gytis Raudonius
Gytis Raudonius 2016 年 11 月 1 日
solve added code
curs = exec(conn, sqlquery);
setdbprefs('DataReturnFormat','cellarray');
curs = fetch(curs);
vardas = curs.data(1,1);

サインインしてコメントする。

その他の回答 (0 件)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by