Tquery的一个问题

jumphigh 2000-08-19 04:24:00
像要实现一个从memo1读入数据至数据库中的sql
可是运行连连出错

Project card_pro.exe raised exception class EnoResultset with message 'Error creating cursor handle'. Process stopped. Use Step or Run to continuse.

Project card_pro.exe raised exception class EDBEngineError with message 'Key violation'. Process stopped.Use Step or Run to continuse.


var
i:integer;
len:integer;
position:integer;
str1:string;
str2:string;
begin

for i:=0 to memo1.Lines.Count-1 do
begin
str1:=memo1.Lines.Strings[i];
len:=length(str1)-1;
position:=pos('[',str1)-1;
str2:=copy(str1,position,len-position);
str1:=copy(str1,0,position);

with query1 do
begin
Close;
sql.Clear;
sql.Add('INSERT INTO "Vcard.db" (Vspelling,Vexplain)');
sql.Add('VALUES (:spelling,:explain)');
ParamByName('spelling').AsString:=str1;
ParamByName('explain').AsMemo:=str2;
end;
try
query1.Open;
except
query1.ExecSQL;
end; //edntry

end; //endfor

end;
...全文
111 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
jumphigh 2000-08-20
  • 打赏
  • 举报
回复
多谢指教
Michaelyfj 2000-08-19
  • 打赏
  • 举报
回复
前三位师兄说的都很好,我就不再补充了...
zsr 2000-08-19
  • 打赏
  • 举报
回复
一般来说,需要返回结果用open,否则Execsql;
lotto 2000-08-19
  • 打赏
  • 举报
回复
如果你要修改数据库中的数据,如insert,delete,update等需要使用execsql;
应该将代码改为:
try
query1.execsql;
except
//error message...
end;
如果str1,str2中含有“'”,“ ,” 等符号也容易发生错误
shylsz 2000-08-19
  • 打赏
  • 举报
回复
问题在于
try
query1.open;
except
query1.execsql;
end;
应改成
try
query1.execsql;
except
showmessage('数据库提交失败');
end;

5,387

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 开发及应用
社区管理员
  • VCL组件开发及应用社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧