Update row in database
古いコメントを表示
Hi ..
In database I have Id and its type is 'int', also I have Name and its type is varchar
When I tried to update the Id it was work:
Id = str2num(get(handles.ID,'String'));
y = exec(conn,'select Id from admin_info')
y = fetch(y);
y1=(y.Data)
colnames3={'Id'};
whereclause3 = ['WHERE ID= ' num2str(y1{1})]
update(conn,'admin_info', colnames3, Id, whereclause3);
But the update for the name it doesn't work !
name = get(handles.name, 'String')
x = exec(conn,'select name from admin_info');
x = fetch(x);
x1 = x.Data
n = x1{1}
colnames2={'name'};
whereclause2 = ['WHERE name = ' n]
update(conn,'admin_info', colnames2, name, whereclause2);
7 件のコメント
Han
2018 年 3 月 21 日
Bob Thompson
2018 年 3 月 21 日
Is it giving you a specific error? If so would you please post it along with which line is causing the error.
Also, what type of variable is 'n'?
Han
2018 年 3 月 21 日
Bob Thompson
2018 年 3 月 21 日
Ok, if there is not error how do you know that it is wrong? What results is it giving you, and what would you expect?
Han
2018 年 3 月 21 日
Bob Thompson
2018 年 3 月 21 日
I realize this is things you probably already checked, but it's what I usually go through to investigate my errors.
Have you confirmed that name, n, and whereclause2 are all proper values and classes?
If those are all correct, then it appears that all of the inputs to the update() command are correct and I don't know that I'm really going to be able to help you much, since I don't really know anything about Simulink commands.
I may be way off here (not a lot of experience with databases), but:
It looks like you are retrieving the entire column from the database, using MATLAB to find the row you want to change, then telling the database to change it. Why not build a single exec command and let the database do it all?
Otherwise, I notice you have a space before the = in the second where clause, but not the first. I don't think that matters, but maybe?
採用された回答
その他の回答 (1 件)
Han
2018 年 3 月 22 日
1 件のコメント
That is extremely complex code.
x = exec(conn,'select name from admin_info');
x = fetch(x);
colnames2={'name'};
% Probably want an actual index here, not a hardcoded 1
whereclause2 = sprint('WHERE name = ''%s''',x.Data{1});
Your use of
xx = char(x.Data);
will not do well when x.Data has multiple rows.
カテゴリ
ヘルプ センター および File Exchange で Structures についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!