Write in SQL-Database

조회 수: 1 (최근 30일)
HaDu
HaDu 2017년 8월 10일
편집: Jayaram Theegala 2017년 8월 15일
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