Update database in gui but dont get updated data.
Show older comments
HI, i try to update database in gui, but my code dont working and dont get error also database not updated please help me. there is table:

code
function pushbutton2_Callback(hObject, eventdata, handles)
colnames = {'vardas','pavarde','laipsnis','pareigos','telefonas','marke','numeris','tarnyba'};
conn = database('baze', 'root', 'root', 'Vendor', 'MYSQL', 'Server', 'localhost', 'PortNumber', 3306);
set(conn, 'AutoCommit', 'on');
get(conn, 'AutoCommit');
update(conn, 'info', colnames,{handles.edit1,handles.edit2,handles.edit3,handles.edit4,handles.edit5,handles.edit6,handles.edit7,handles.edit8},['where id = ' sprintf('%f',handles.text9)])
close(conn);
Answers (1)
Geoff Hayes
on 3 Jun 2017
Gytis - in your command
update(conn, 'info', colnames, ...
{handles.edit1,handles.edit2,handles.edit3,handles.edit4,handles.edit5,handles.edit6,handles.edit7,handles.edit8},...
['where id = ' sprintf('%f',handles.text9)])
you are populating the cell array of values with the handles of the edit controls rather than the strings that have been entered in to each edit control. Rather than using the handle, you will need to extract the string first
vardasValue = get(handles.edit1,'String');
(though this will depend upon which version of MATLAB that you are using).
4 Comments
Gytis Raudonius
on 3 Jun 2017
Geoff Hayes
on 3 Jun 2017
Put a breakpoint in the code and then check to see what the command is that you are submitting to the database. Also, what is your where clause? Your code (unless changed) is
['where id = ' sprintf('%f',handles.text9)]
Again, you will need to do
id = get(handles.text9, 'String');
and
['where id = ' id ]
Gytis Raudonius
on 3 Jun 2017
Geoff Hayes
on 3 Jun 2017
Gytis - you will have to post all of your code so that I can see what you've written. From the error, it sounds like you have two where clauses...
Categories
Find more on Database Toolbox in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!