procedure Thpxxglfm.cxbtClick(Sender: TObject);
var
i:integer;
str,str1,str2,str3:string;
begin
i:=1;
if (trim(cxtjbox.Text) ='')or (trim(sredit.Text )='') then //查询条件是combobox,其中有货品编码,货品名称,货品品类
begin
showmessage('请输入完整的查询信息!');
exit;
end;try
str:='select * from 货品信息表 where';
case cxtjbox.ItemIndex of
0:
begin
str:=str+'货品编码:=sr';
str1:=str;
i:=1;
end;
1:
begin
str:=str+'货品名称:=sr';
str2:=str;
i:=2;
end;
2:
begin
str:=str+'货品品类:=sr';
str3:=str;
i:=3;
end;
end;
with adoquery1 do
begin
close;
sql.Clear;
sql.Add(str);
parameters.ParamByName('sr').Value :=trim(sredit.Text );
open;
first;
if recordcount=0 then
begin
showmessage('没有符合条件的查询!');
sredit.SetFocus ;
exit;
end
else
begin
case i of
1: begin
with adoquery2 do
begin;
close;
sql.Clear;
sql.Add('select * from 货品信息表 where 货品编码=hpbm');
parameters.ParamByName('hpbm').Value :=trim(sredit.Text);
open;
with stringgrid1 do
begin
cells[0,1]:=fieldbyname('货品编码').AsString ;
cells[1,1]:=fieldbyname('货品名称').AsString ;
cells[2,1]:=fieldbyname('货品品类').AsString ;
cells[3,1]:=fieldbyname('单位').AsString ;
cells[4,1]:=fieldbyname('仓库编码').AsString ;
cells[5,1]:=fieldbyname('仓库名称').AsString ;
cells[6,1]:=fieldbyname('进货价').AsString ;
cells[7,1]:=fieldbyname('原始库存').AsString ;
cells[8,1]:=fieldbyname('警戒底线库存').AsString;
cells[9,1]:=fieldbyname('警戒高线库存').AsString;
end;
end;
end;
2: begin
with adoquery2 do
begin
close;
sql.Clear;
sql.Add('select * from 货品信息表 where 货品名称='+''''+sredit.Text+'''');
open;
with stringgrid1 do
begin
cells[0,1]:=fieldbyname('货品编码').AsString ;
cells[1,1]:=fieldbyname('货品名称').AsString ;
cells[2,1]:=fieldbyname('货品品类').AsString ;
cells[3,1]:=fieldbyname('单位').AsString ;
cells[4,1]:=fieldbyname('仓库编码').AsString ;
cells[5,1]:=fieldbyname('仓库名称').AsString ;
cells[6,1]:=fieldbyname('进货价').AsString ;
cells[7,1]:=fieldbyname('原始库存').AsString ;
cells[8,1]:=fieldbyname('警戒底线库存').AsString ;
cells[9,1]:=fieldbyname('警戒高线库存').AsString ;
end;
end;
end;
3: begin
with adoquery2 do
begin
close;
sql.Clear;
sql.Add('select * from 货品信息表 where 货品品类='+''''+sredit.Text+'''');
open;
with stringgrid1 do
begin
cells[0,1]:=fieldbyname('货品编码').AsString ;
cells[1,1]:=fieldbyname('货品名称').AsString ;
cells[2,1]:=fieldbyname('货品品类').AsString ;
cells[3,1]:=fieldbyname('单位').AsString ;
cells[4,1]:=fieldbyname('仓库编码').AsString ;
cells[5,1]:=fieldbyname('仓库名称').AsString ;
cells[6,1]:=fieldbyname('进货价').AsString ;
cells[7,1]:=fieldbyname('原始库存').AsString ;
cells[8,1]:=fieldbyname('警戒底线库存').AsString ;
cells[9,1]:=fieldbyname('警戒高线库存').AsString ;
end;
end;
end;
end;
end;
end;
查询结果用stringgrid显示,adoquery1,adoquery2都已连好
var
i:integer;
str,str1,str2,str3:string;
begin
i:=1;
if (trim(cxtjbox.Text) ='')or (trim(sredit.Text )='') then //查询条件是combobox,其中有货品编码,货品名称,货品品类
begin
showmessage('请输入完整的查询信息!');
exit;
end;try
str:='select * from 货品信息表 where';
case cxtjbox.ItemIndex of
0:
begin
str:=str+'货品编码:=sr';
str1:=str;
i:=1;
end;
1:
begin
str:=str+'货品名称:=sr';
str2:=str;
i:=2;
end;
2:
begin
str:=str+'货品品类:=sr';
str3:=str;
i:=3;
end;
end;
with adoquery1 do
begin
close;
sql.Clear;
sql.Add(str);
parameters.ParamByName('sr').Value :=trim(sredit.Text );
open;
first;
if recordcount=0 then
begin
showmessage('没有符合条件的查询!');
sredit.SetFocus ;
exit;
end
else
begin
case i of
1: begin
with adoquery2 do
begin;
close;
sql.Clear;
sql.Add('select * from 货品信息表 where 货品编码=hpbm');
parameters.ParamByName('hpbm').Value :=trim(sredit.Text);
open;
with stringgrid1 do
begin
cells[0,1]:=fieldbyname('货品编码').AsString ;
cells[1,1]:=fieldbyname('货品名称').AsString ;
cells[2,1]:=fieldbyname('货品品类').AsString ;
cells[3,1]:=fieldbyname('单位').AsString ;
cells[4,1]:=fieldbyname('仓库编码').AsString ;
cells[5,1]:=fieldbyname('仓库名称').AsString ;
cells[6,1]:=fieldbyname('进货价').AsString ;
cells[7,1]:=fieldbyname('原始库存').AsString ;
cells[8,1]:=fieldbyname('警戒底线库存').AsString;
cells[9,1]:=fieldbyname('警戒高线库存').AsString;
end;
end;
end;
2: begin
with adoquery2 do
begin
close;
sql.Clear;
sql.Add('select * from 货品信息表 where 货品名称='+''''+sredit.Text+'''');
open;
with stringgrid1 do
begin
cells[0,1]:=fieldbyname('货品编码').AsString ;
cells[1,1]:=fieldbyname('货品名称').AsString ;
cells[2,1]:=fieldbyname('货品品类').AsString ;
cells[3,1]:=fieldbyname('单位').AsString ;
cells[4,1]:=fieldbyname('仓库编码').AsString ;
cells[5,1]:=fieldbyname('仓库名称').AsString ;
cells[6,1]:=fieldbyname('进货价').AsString ;
cells[7,1]:=fieldbyname('原始库存').AsString ;
cells[8,1]:=fieldbyname('警戒底线库存').AsString ;
cells[9,1]:=fieldbyname('警戒高线库存').AsString ;
end;
end;
end;
3: begin
with adoquery2 do
begin
close;
sql.Clear;
sql.Add('select * from 货品信息表 where 货品品类='+''''+sredit.Text+'''');
open;
with stringgrid1 do
begin
cells[0,1]:=fieldbyname('货品编码').AsString ;
cells[1,1]:=fieldbyname('货品名称').AsString ;
cells[2,1]:=fieldbyname('货品品类').AsString ;
cells[3,1]:=fieldbyname('单位').AsString ;
cells[4,1]:=fieldbyname('仓库编码').AsString ;
cells[5,1]:=fieldbyname('仓库名称').AsString ;
cells[6,1]:=fieldbyname('进货价').AsString ;
cells[7,1]:=fieldbyname('原始库存').AsString ;
cells[8,1]:=fieldbyname('警戒底线库存').AsString ;
cells[9,1]:=fieldbyname('警戒高线库存').AsString ;
end;
end;
end;
end;
end;
end;
查询结果用stringgrid显示,adoquery1,adoquery2都已连好
解决方案 »
- 在線高分求助﹕delphi6 設置lookupcache為true時﹐發生末知錯誤﹔設為false時﹐lookup類型數據不能顯示
- 哪位大侠有做过读写24cxx芯片的delphi实例啊
- 特急急急!!!'IsEmpty'不是可识别的函数名' ‘update history set arr1= iif(IsEmpty(arr1),@time,arr1) where his_date=@his_date
- 请问Delphi有没有象做网页中editer控件
- Delphi自带的Mediaplayer在98下录音的问题
- 我出1000分解决这个问题(另外开贴)--主从表删除后保存出错
- 请问如何拦截listview改变列宽度,托动水平、垂直滚动条事件?
- 上个相关问题已给分,接着问!
- 为什么能获得另一个程序的MEMO等控件的内容,却不能获得LISTBOX控件的内容(附代码)?
- 这段代码如何简写呢?
- 如何在一个程序中控制另一个程序的按钮被点击?
- 关于网络文件传输,用的控件clientsocket和serversocket.
parameters.ParamByName('hpbm').Value :=trim(sredit.Text);你最好把出错的现象写下来,别人容易判断些。
case cxtjbox.ItemIndex of
0:
begin
str:=str+'货品编码:=sr';
str1:=str;
i:=1;
end;
根据你上面的代码,你的sql语句应该是这样的
select * from 货品信息表 where货品编码:=sr
这有两个错误
1、where 和“货品编码”之间没有空格
2/、赋值应该这样写 货品编码=:sr 冒号应该在后边,sql中的赋值是"=",:代表后边的是参数