Write in SQL-Database

1 visualización (últimos 30 días)
HaDu
HaDu el 10 de Ag. de 2017
Editada: Jayaram Theegala el 15 de Ag. de 2017
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

Respuestas (1)

Jayaram Theegala
Jayaram Theegala el 15 de Ag. de 2017
Editada: Jayaram Theegala el 15 de Ag. de 2017
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!

Etiquetas

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by