Delphi EOleexception 第一行:‘0’附近有语法错误

with adoquery1 do
begin
close;
sql.Clear;
sql.Add('select * from varview');
open;
end;

if adoquery1.isempty then
with adoquery1 do
begin
close;
sql.clear;
sql.add('insert into varview (RunSign,ChargingSign,DisChargingSign,OverASign,OverVSign,UnderVSign) values('''+inttostr(f1)+''','''+inttostr(f2)+''','''+inttostr(f3)+''','''+inttostr(f4)+''','''+inttostr(f5)+''','''+inttostr(f6)+'''');
execsql;
end
else
with adoquery1 do
begin
close;
sql.clear;
sql.add('update varview set RunSign='''+inttostr(f1)+''',ChargingSign='''+inttostr(f2)+''',DisChargingSign='''+inttostr(f3)+''',OverASign='''+inttostr(f4)+''',OverVSign='''+inttostr(f5)+''',UnderVSign='''+inttostr(f6)+'''');
execsql;
end;
编译没问题,运行到execsql就报错;

Insert语句错误
应该是 sql.add('insert into varview (RunSign,ChargingSign,DisChargingSign,OverASign,OverVSign,UnderVSign) values('''+inttostr(f1)+''','''+inttostr(f2)+''','''+inttostr(f3)+''','''+inttostr(f4)+''','''+inttostr(f5)+''','''+inttostr(f6)+''')');

少了一个右括号
本身sql.add() 这里一对括号
Insert into varview () values () 这里也有两队括号.

你问这种问题本身没什么意义,写错谁都有可能。
你的问题是,你不知道怎么去调试。
你可以这样写
var sql :string;
sql='insert into varview (RunSign,ChargingSign,DisChargingSign,OverASign,OverVSign,UnderVSign) values('''+inttostr(f1)+''','''+inttostr(f2)+''','''+inttostr(f3)+''','''+inttostr(f4)+''','''+inttostr(f5)+''','''+inttostr(f6)+'''';
然后
with adoquery1 do
begin
close;
sql.clear;
sql.add(sql);
execsql;
end;

断点放在execsql这一行,监控sql语句,拷贝下来在数据库工具上执行就知道哪里错了
小技巧:在调试时,可以按住Ctrl,鼠标左键点击sql,然后你就可以拷贝sql语句了
温馨提示:答案为网友推荐,仅供参考
第1个回答  2013-12-13
运行到execsql就报错那就说明SQL语句一定有语法错误!

可以通过加Try..except..end获取到错误信息,再做处理:
try
with adoquery1 do
begin
close;
sql.Clear;
sql.Add('select * from varview');
open;
end;

if adoquery1.isempty then
with adoquery1 do
begin
close;
sql.clear;
sql.add('insert into varview (RunSign,ChargingSign,DisChargingSign,OverASign,OverVSign,UnderVSign) values('''+inttostr(f1)+''','''+inttostr(f2)+''','''+inttostr(f3)+''','''+inttostr(f4)+''','''+inttostr(f5)+''','''+inttostr(f6)+'''');
execsql;
end
else
with adoquery1 do
begin
close;
sql.clear;
sql.add('update varview set RunSign='''+inttostr(f1)+''',ChargingSign='''+inttostr(f2)+''',DisChargingSign='''+inttostr(f3)+''',OverASign='''+inttostr(f4)+''',OverVSign='''+inttostr(f5)+''',UnderVSign='''+inttostr(f6)+'''');
execsql;
end;
Except
on E:Except do
showmessage(e.message);
end;
第2个回答  2013-12-14
应该是 sql.add('insert into varview (RunSign,ChargingSign,DisChargingSign,OverASign,OverVSign,UnderVSign) values('''+inttostr(f1)+''','''+inttostr(f2)+''','''+inttostr(f3)+''','''+inttostr(f4)+''','''+inttostr(f5)+''','''+inttostr(f6)+''')';