hi, i have a problem now and i think many people like me! please help, i tried to solve it but i can't

i have a code below:
...
i = curs.Data{1}
update(connA, 'inputtb', {'Timeout'}, {'out'}, 'where ID = i')
...
in my project, ''i'' isn't constant. Because every time I find ID in my database, it return a new curs.Data{1} so I want ''i'' were a variable. Any time it return curs.Data{1}, the code update (below) will be execute, and ''i'' was imported value from curs.Data{1}. The problem is in whereclause, it seem like we can't put one variable into place ''i'' above!

Answers (2)

Try making it a string with the number embedded with sprintf():
theQuery = sprintf('where ID = %d', i);
curs.Data{1} update(connA, 'inputtb', {'Timeout'}, {'out'}, theQuery)
By the way, having many people "like" you is not a problem - it's great. You have many friends. Better than have many people hate you. :-)
I mean many people has the same problem like me.(my english is bad ^^)
thank for suggestion, i tried but it doesn't work.
I want to update my datable table in MS ACCESS with a specific row was a variable, not constant. I had defined the ODBC data resource with Matlab database toolbox.
example, in image below, i want to update row ID 5, Timeout from ''in'' to ''out'' but not use the code: update(connA, 'inputtb', {'Timeout'}, {'out'}, where ID = 5')

4 Comments

Please post comments in the comment section, not as new answer.
Instead of writing "it doesn't work", a more detailed description of the occurring problems would be more helpful to suggest an improvement.
Image Analysts's suggestion seems to be perfect already:
id = 5;
theQuery = sprintf('where ID = %d', id)
update(connA, 'inputtb', {'Timeout'}, {'out'}, theQuery)
So what happens if you do this?
hi Jan simon, i'm really sorry. first, my english is bad, and this is my first post on mathwork. i'm really ashame about that!
i had run your code and there was an error:
Error using database/update (line 162) [Microsoft][ODBC Microsoft Access Driver] Too few parameters. Expected 1.
Error in updateh_dataout (line 60) update(connA, 'inputtb', {'Timeout'}, {'out'}, theQuery)
i use matlab R2012a.
i think there is a structure when use variable, example the code below:
idtmp = tmp
curs = exec(connA, ['select * from inputtb where Barcode = ' '''' idtmp '''']);
idtmp is a variable. i coded and it ran ok!
but with sql update, what's the structure for variable?
I'm not sure what you're asking. What's your code for using the update() function? Actually I haven't used MATLAB with databases, so I'm not going to be any help.

Sign in to comment.

Asked:

on 1 May 2013

Community Treasure Hunt

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

Start Hunting!