query数据库问题?调试了一星期无法通过,谁告诉我是为什么?

later 2003-05-19 07:01:17
我想用edit1 edit2实现数据的修改
可是系统无法获得通过!
用这种方式解决,可是系统说query找不到ID字段,下面的没有错哦
with query1 do
begin
close;
sql.Clear;
sql.Add('update COURSE ');
sql.Add('set classroom ='''+edit1.Text +''',classtime ='''+edit2.Text+''',state=''3''');
sql.Add('where ID ='''+query1.parambyname('ID').asstring+'''');
prepare;
open;
end;
谁救救我哦
...全文
61 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
JInyk 2003-05-21
  • 打赏
  • 举报
回复

我想用edit1 edit2实现数据的修改
可是系统无法获得通过!
用这种方式解决,可是系统说query找不到ID字段,下面的没有错哦
with query1 do
begin
close;
sql.Clear;
sql.Add('update COURSE ');
sql.Add('set classroom ='''+edit1.Text +''',classtime ='''+edit2.Text+''',state=''3''');
sql.Add('where ID ='''+query1.parambyname('ID').asstring+'''');
prepare;
open;
end;


倒数第四行的 query1.parambyname('ID').asstring+''''); 错了
query1.fieldbyname('ID').asstring+'''');



ihihonline 2003-05-21
  • 打赏
  • 举报
回复
//
var
vIndex : String;
begin

...
...
vIndex := Query1.FieldByName('ID').AsString;
with query1 do
begin
close;
sql.Clear;
sql.Add('update COURSE ');
sql.Add('set classroom ='''+edit1.Text +''',classtime ='''+edit2.Text+''',state=''3''');
sql.Add('where ID ='''+vIndex+'''');
prepare;
open;

end;
cow8063 2003-05-21
  • 打赏
  • 举报
回复
query1.parambyname('ID').asstring 怎么有这个 的
这样
query1.fieldbyname('ID').asstring
xiehua822 2003-05-20
  • 打赏
  • 举报
回复
up
不停歇的步伐 2003-05-20
  • 打赏
  • 举报
回复
id有可能是关键字,你换一个名称试试
飞天林 2003-05-19
  • 打赏
  • 举报
回复
up
888888888888 2003-05-19
  • 打赏
  • 举报
回复
关注
later 2003-05-19
  • 打赏
  • 举报
回复
刀崽兄
可不可以告诉我 你到哪里学到的这么专业的 delphi知识啊?
介绍本好书撒 ^_^
foilsman 2003-05-19
  • 打赏
  • 举报
回复
上面的
sql.Add(' where [ID] =' ' + QuotedStr(query2.parambyname('ID').asstring));
改为
sql.Add(' where [ID] =' + QuotedStr(query2.parambyname('ID').asstring));
foilsman 2003-05-19
  • 打赏
  • 举报
回复
with query1 do
begin
close;
sql.Clear;
sql.Add('update COURSE ');
sql.Add('set classroom =' + QuotedStr(edit1.Text) + ',classtime =' + QuotedStr(edit2.Text) + ',state=' + QuotedStr('3'));
sql.Add(' where [ID] =' ' + QuotedStr(query2.parambyname('ID').asstring));
execsql;
end;

注:
//不能把
sql.Add(' where [ID] =' ' + QuotedStr(query2.parambyname('ID').asstring));
写成如下
sql.Add(' where [ID] =' ' + QuotedStr(query1.parambyname('ID').asstring));//query1
//要不你另想办法得到该条件值.
大健 2003-05-19
  • 打赏
  • 举报
回复
with query1 do
begin
close;
sql.Clear;
sql.Add('update COURSE set ');
sql.Add(' classroom=:classroom,classtime=:classtime,state=''3'' ');
sql.Add('where [ID] =:id');
parambyname('classroom').asstring:=edit1.Text;
parambyname('classtime').asstring:=edit2.Text;
parambyname('id').asstring:=edit3.Text;
prepare;
open;
end;

2,497

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 数据库相关
社区管理员
  • 数据库相关社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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