Update database in gui but dont get updated data.
显示 更早的评论
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);
回答(1 个)
Geoff Hayes
2017-6-3
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 个评论
Gytis Raudonius
2017-6-3
Geoff Hayes
2017-6-3
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
2017-6-3
Geoff Hayes
2017-6-3
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...
类别
在 帮助中心 和 File Exchange 中查找有关 Database Toolbox 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!