请大家帮我看一段代码

sunshineboy810921 2004-11-04 03:34:19
我写了这样的一个查询窗体,(注:combobox1中的值为bookin表中的几个字段)
我现在想实现,当我从combobox1中选择一个字段,然后再在edit1中输入内容
单击"确定"按钮来查询想要找的内容,然后把查询到的内容在dbgrid中显示,
以下写的代码也不知道那里有问题
请指导,谢谢!
with dm.query2 do
begin
close;
sql.Clear;
sql.Add('select * from bookin where combobox1.text=:E');
Parameters.ParamByName('E').Value:=trim(edit1.Text);
prepared:=true;
open;
end;
...全文
92 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
todouwang 2004-11-04
  • 打赏
  • 举报
回复
这样写
params.ParamByName('E').Value:=trim(edit1.Text);
coeltdit 2004-11-04
  • 打赏
  • 举报
回复
var
Str: String;
begin
with dm.query2 do
begin
close;
sql.Clear;
sql.Add('select * from bookin where Str = :E');
Parameters.ParamByName('E').Value:=trim(edit1.Text);
prepared:=true;
open;
end;
end; // 这样就不用担心引号的问题了; ~—~

gechaosa 2004-11-04
  • 打赏
  • 举报
回复
with dm.query2 do
begin
close;
sql.Clear;
sql.Add('select * from bookin where ' + combobox1.text + ' = :E');
Parameters.ParamByName('E').Value:=trim(edit1.Text);
prepared:=true;
open;
end;

or with dm.query2 do
begin
close;
sql.Clear;
sql.Add('select * from bookin where ' + combobox1.text + ' = '+''''+trim(edit1.Text)+'''');
prepared:=true;
open;
end;
zdq801104 2004-11-04
  • 打赏
  • 举报
回复
querystr:=combobox1.text+'='+''''+edit1.Text+'''';

adodataset.CommandText:='select * from MaintManView where '+querystr;

这样就不会错了嘛!错拉来找我,^_^!
zdq801104 2004-11-04
  • 打赏
  • 举报
回复
有没有错,把括号去掉放到查询分析器调试不就知道了?
warmworm 2004-11-04
  • 打赏
  • 举报
回复
faint
楼上的,你楼上的错了,哪有在查询字段两边加引号的
而且如果QUERY用Parameters的,即使是字符串也不用加引号在原来的SQL语句的
xfgncit98 2004-11-04
  • 打赏
  • 举报
回复
同意楼上的。
jianghd 2004-11-04
  • 打赏
  • 举报
回复
with dm.query2 do
begin
close;
sql.Clear;
sql.Add('select * from bookin where ''' + combobox1.text + ''' = :E');
Parameters.ParamByName('E').Value:=trim(edit1.Text);
prepared:=true;
open;
end;
warmworm 2004-11-04
  • 打赏
  • 举报
回复
--> sql.Add('select * from bookin where combobox1.text=:E');
sql.Add( 'Select * From bookin where ' + combobox1.text + '=:E' );

2,507

社区成员

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

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