窗体中有两个名为edit1,edit2的Tedit,想当edit2输入ID号时,edit1 显示相应数据库的内容,以下是代码,但是问题是,第一次双击edit2时,edit1能正确显示内容,但是修改edit2ID号,再次click时,却依然显示第一次双击时,显示的内容,如:第一次edit2,输入1,双击,edit1正确显示:新年好;将edit2输入2,再双击,edit1依然显示:新年好.本来应该显示:恭喜发财.谢谢大家啦...
procedure Tkssz.Edit2DblClick(Sender: TObject);
begin
try
adoquery1.close;
adoquery1.Connection:=form1.ADOConnection1;
adoquery1.SQL.Add('select section_name from section where section_id='+Quotedstr(edit2.Text));
adoquery1.open;
if not adoquery1.isEmpty then
begin
edit1.Text:= adoquery1.fieldbyname('section_name').Value;
end;
except
raise;
end
end;
procedure Tkssz.Edit2DblClick(Sender: TObject);
begin
try
adoquery1.close;
adoquery1.Connection:=form1.ADOConnection1;
adoquery1.SQL.Add('select section_name from section where section_id='+Quotedstr(edit2.Text));
adoquery1.open;
if not adoquery1.isEmpty then
begin
edit1.Text:= adoquery1.fieldbyname('section_name').Value;
end;
except
raise;
end
end;
解决方案 »
- 求cxgrid中职员信息的demo
- 我的程序编译时,弹出一个标题为CPU的对话框?不知什么回事
- !!!!!跪求帮忙!!!!!
- 如何在局域网里实现接收短消息
- 【英雄帖】各路好手:英雄有武之地了
- 请英文比较好、而且对图象处理方面的术语比较懂的兄弟帮我翻译一些名词,先谢谢了。200分。
- 谁有兴趣做网络游戏外挂啊!市场前景广阔!泰山工作室赚了500多万
- 在Form的OnShow事件中Close窗体,我找到一个方法,但是仍然有缺陷。能帮我看看吗?
- 如何获得系统时间?
- 怪事,Stringgrid中的数值显示问题
- <急救> 在Delphi中 如何查询DB数据表里面的一条记录```谢谢`
- 有人对delphi和flash采用ExternalInterface交互熟悉么?
begin
try
Edit1.text := '';
adoquery1.close;
adoquery1.Connection:=form1.ADOConnection1;
adoquery1.SQL.Add('select section_name from section where section_id='+Quotedstr(edit2.Text));
adoquery1.open;
if not adoquery1.isEmpty then
begin
edit1.Text:= adoquery1.fieldbyname('section_name').Value;
end;
except
raise;
end
end; 這裏要注意兩個問題。查詢前先把EDIT裏的內容清除掉。另外就是要確定輸入第二次的值後SQL能返回數據,那麼EDIT1.text 才可能有值
begin
try
Edit1.text := '';
adoquery1.close;
adoquery1.Connection:=form1.ADOConnection1;
adoquery1.SQL.Add('select section_name from section where section_id='+Trim(edit2.Text));
adoquery1.open;
if not adoquery1.isEmpty then
begin
edit1.Text:= adoquery1.fieldbyname('section_name').asString;
end;
except
raise;
end
end;
begin
try
Edit1.text := '';
adoquery1.close;
adoquery1.Connection:=form1.ADOConnection1;
adoquery1.SQL.text :='select section_name from section where section_id='+Trim(edit2.Text); // 用 sql.text 或者sql.clear; 後再sql.add
adoquery1.open;
if not adoquery1.isEmpty then
begin
edit1.Text:= adoquery1.fieldbyname('section_name').asString;
end;
except
raise;
end
end;
begin
try
Edit1.text := '';
adoquery1.close;
adoquery1.Connection:=form1.ADOConnection1;
adoquery1.SQL.text :='select section_name from section where section_id='+Trim(edit2.Text); // 用 sql.text 或者sql.clear; 後再sql.add
adoquery1.open;
if not adoquery1.isEmpty then
begin
edit1.Text:= adoquery1.fieldbyname('section_name').asString;
end;
except
raise;
end
end;
begin
try
adoquery1.close;
adoquery1.Connection:=form1.ADOConnection1;
adoquery1.clear; // 要先清空语句
adoquery1.SQL.Add('select section_name from section where section_id='+Quotedstr(edit2.Text));
adoquery1.open;
if not adoquery1.isEmpty then
begin
edit1.Text:= adoquery1.fieldbyname('section_name').Asstring;
end;
except
raise;
end
end;