Write in SQL-Database

3 次查看(过去 30 天)
HaDu
HaDu 2017-8-10
Hello everybody, currently I have a problem with writing data in a SQL database.
for k=rowstart+1:size(GivenDB,2) %go through columns
for L=2:size(GivenDB,1) %go through lines
momSpaltenname=GivenDB{1,k}; %name of the column
momZelleninhalt=GivenDB{L,k}; %content of the cell
momZeile=GivenDB{L,1}; %current line
query= sprintf('UPDATE Kennzahlen SET %s = %f WHERE %s = %f',momSpaltenname,momZelleninhalt,Par_DBLaufindex,momZeile);
exec(conn, query);
end
end
The content of the cell is sometimes a number and sometimes a string. My guess is, that is the problem, but I don't know how to fix it.
the error massage:
Error using sqlite/exec
Received exception (SQL error or missing database D:\Hasan\Matlab Skri\DB_Krallmann_CX50_orig.db. (near "WHERE":
syntax error)) upon attempting an operation; details: UPDATE Kennzahlen SET Auftrag_Nummer = WHERE CycID =
280571.000000.
Error in FILENAME (line 224)
exec(conn, query);
cellarray "a" is the part of "GivenDB", which I want to write in the database. If you need more information, don't hesitate to ask.
edit:updated the workspace-file

回答(1 个)

Jayaram Theegala
Jayaram Theegala 2017-8-15
编辑:Jayaram Theegala 2017-8-15
As you mentioned, the error that you are facing could be because of the difference in the datatype of the cell contents. If the value that you are trying to SET is of string type, you are currently not surrounding that value with single or double quotes. Hence, if you determine the value you are trying to update is of string type, you can create the query in such a way that the value is enclosed with single or double quotes.
Also to troubleshoot, you can set break points and see what the actual query is, before calling the "exec" command, and make sure that the query is syntactically correct. I hope this helps!

类别

Help CenterFile Exchange 中查找有关 Database Toolbox 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by