我正在开发一个程序来使用 sql server 更新 delphi 7 中表中的某些字段。程序是这样的:
sql := 'UPDATE tb_dt_contract SET '
+' id_schedule = '+quotedstr(label_id_schedule.Caption)
+',start_date = '+quotedstr(formatdatetime('mm/dd/yyyy',DateTime_start.Date))
+',finish_date = '+quotedstr(formatdatetime('mm/dd/yyyy',DateTime_finish.Date))
+',contract_location = '+quotedstr(uppercase(Edit_location.Text))
+',sign_date = '+quotedstr(formatdatetime('mm/dd/yyyy',DateTime_sign.Date))
+' WHERE id = '+quotedstr(label_id.Caption);
ADOQuery1.Close;
ADOQuery1.SQL.Text := sql;
ADOQuery1.ExecSQL;
当我运行程序时,它给了我一个错误:'=''附近的语法不正确。但是当我使用 showmessage 查看查询并在 sql server management 2008 中运行它时,它工作正常。
然后我尝试将查询拆分为如下部分:
SQL := 'UPDATE tb_dt_contract SET '
+' id_schedule = '+QUOTEDSTR(label_id_schedule.CAPTION)
+' WHERE id = '+quotedstr(label_id.Caption);
ADOQuery1.Close;
ADOQuery1.SQL.Text := sql;
ADOQuery1.ExecSQL;
SQL := 'UPDATE tb_dt_contract SET '
+' start_date = '+quotedstr(formatdatetime('mm/dd/yyyy',DateTime_start.Date))
+' WHERE id = '+quotedstr(label_id.Caption);
ADOQuery1.Close;
ADOQuery1.SQL.Text := sql;
ADOQuery1.ExecSQL;
SQL := 'UPDATE tb_dt_contract SET '
+' finish_date = '+quotedstr(formatdatetime('mm/dd/yyyy',DateTime_finish.Date))
+' WHERE id = '+quotedstr(label_id.Caption);
ADOQuery1.Close;
ADOQuery1.SQL.Text := sql;
ADOQuery1.ExecSQL;
SQL := 'UPDATE tb_dt_contract SET '
+' contract_location = '+quotedstr(uppercase(edit_location.Text))
+' WHERE id = '+quotedstr(label_id.Caption);
ADOQuery1.Close;
ADOQuery1.SQL.Text := sql;
ADOQuery1.ExecSQL;
SQL := 'UPDATE tb_dt_contract SET '
+' sign_date = '+quotedstr(formatdatetime('mm/dd/yyyy',DateTime_sign.Date))
+' WHERE id = '+quotedstr(label_id.Caption);
ADOQuery1.Close;
ADOQuery1.SQL.Text := sql;
ADOQuery1.ExecSQL;
然后我发现它只在更新日期类型字段时触发错误。我开发了其他程序来使用类似的查询更新不同的表,它工作正常。我尝试关闭项目并重新打开它,但它仍然给我那个错误消息。请告诉我我该怎么做..