chaxun.SQL.Clear;
chaxun1.SQL.Add('select shangpin.spdm as 商品代码,sj1 as 原价,je5 as 现价 from shangpin');
chaxun1.SQL.Add('left join (select * from yangxiaojie where khdm like ''%'+ck+'%'' and spdm like ''%'+hh+'%'') as b');
chaxun1.SQL.Add('on shangpin.spdm=b.spdm where shangpin.spdm like ''%'+hh+'%''');
chaxun1.Close;
chaxun1.Open;
end;
为什么我在商品代码里面输入8818 他还会查出88的东西比如 8818 查出来的有778866 388446 ??是不是哪边写错了?
chaxun1.SQL.Add('select shangpin.spdm as 商品代码,sj1 as 原价,je5 as 现价 from shangpin');
chaxun1.SQL.Add('left join (select * from yangxiaojie where khdm like ''%'+ck+'%'' and spdm like ''%'+hh+'%'') as b');
chaxun1.SQL.Add('on shangpin.spdm=b.spdm where shangpin.spdm like ''%'+hh+'%''');
chaxun1.Close;
chaxun1.Open;
end;
为什么我在商品代码里面输入8818 他还会查出88的东西比如 8818 查出来的有778866 388446 ??是不是哪边写错了?
程序出来后.我点仓库代码后的...出来仓库查询框.http://p15.freep.cn/p.aspx?u=v20_p15_p_0805221457199594_0.jpg
然后输入查询值.http://p15.freep.cn/p.aspx?u=v20_p15_p_0805221457507998_0.jpg在dbgird里面双击.查询框关闭.然后代码写入到仓库代码的框内.
http://p15.freep.cn/p.aspx?u=v20_p15_p_0805221458115969_0.jpg这时候点查询可以出来.
http://freep.cn/p.aspx?u=v20__p_0805221459553392_0.jpg但是我换个商品代码再查询就出不来了.
http://freep.cn/p.aspx?u=v20__p_0805221500254269_0.jpg
我的查询框的代码.
unit Unit2;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, DB, Grids, DBGrids, ADODB, StdCtrls, ComCtrls, ExtCtrls,
cxControls, cxPC;type
TForm2 = class(TForm)
DataSource1: TDataSource;
chaxun2: TADOQuery;
Panel1: TPanel;
GroupBox1: TGroupBox;
_cxx: TComboBox;
Label2: TLabel;
Label3: TLabel;
Edit1: TEdit;
Button1: TButton;
DBGrid1: TDBGrid;
procedure FormShow(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure DBGrid1DblClick(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
Procedure OnMouseWheel(Var Msg :TMsg;var Handled:Boolean);
{ Private declarations }
public
{ Public declarations }
end;var
Form2: TForm2;implementation
uses unit1;
{$R *.dfm}procedure TForm2.FormShow(Sender: TObject);
begin
chaxun2.SQL.Clear;
chaxun2.SQL.Add('select ckdm as 仓库代码,ckmc as 仓库名称 from cangku');
chaxun2.close;
chaxun2.Open;
edit1.SetFocus;
_cxx.ItemIndex:= 0;end;procedure TForm2.Button1Click(Sender: TObject);
var hh:string;
begin
hh:=edit1.Text;
if _cxx.text='' then
begin
application.MessageBox('查询项未选择','错误',mb_ok);
end else begin
if _cxx.Text='仓库代码' then
begin
chaxun2.SQL.Clear;
chaxun2.SQL.add('select ckdm as 仓库代码,ckmc as 仓库名称 from cangku');
chaxun2.SQL.Add('where ckdm like ''%'+hh+'%''') ;
chaxun2.Close;
chaxun2.Open;
end else
begin
chaxun2.SQL.Clear;
chaxun2.SQL.add('select ckdm as 仓库代码,ckmc as 仓库名称 from cangku');
chaxun2.SQL.Add('where ckmc like ''%'+hh+'%''') ;
chaxun2.Close;
chaxun2.Open;
end;
end;
end;procedure TForm2.DBGrid1DblClick(Sender: TObject);
beginform1.edit6.text:= chaxun2.FieldByName('仓库代码').AsString;
form2.close;
end;Procedure TForm2.OnMouseWheel(Var Msg :TMsg;var Handled:Boolean);
begin
if Msg.message = WM_MouseWheel then
begin
if Msg.wParam > 0 then
begin
if DBGrid1.Focused then
SendMessage(DBGrid1.Handle,WM_VSCROLL,SB_PAGEUP,0);
end
else
begin
if DBGrid1.Focused then
SendMessage(DBGrid1.Handle,WM_VSCROLL,SB_PAGEDOWN,0);
end;
Handled:= True;
end;
end;procedure TForm2.FormCreate(Sender: TObject);
beginApplication.OnMessage:=OnMouseWheel; // 截获鼠标滚动事件
end;end.
begin
form1.edit6.text:= chaxun2.FieldByName('仓库代码').AsString;
form2.close;
end;
是不是因为form2关闭了的原因?因为我form1的查询是这样.
procedure TForm1.Button3Click(Sender: TObject);
var hh,kh,ck:string;begin
hh:=edit4.Text; ck:=edit6.Text; if hh='' then
begin
application.MessageBox('请输入商品代码!','错误',mb_ok);
edit4.SetFocus;
end else
if ck='' then
begin
application.MessageBox('请输入仓库代码!','错误',mb_ok);
edit6.SetFocus;
end else
begin
chaxun.SQL.Clear;
chaxun1.SQL.Add('select shangpin.spdm as 商品代码,sj1 as 原价,je5 as 现价 from shangpin');
chaxun1.SQL.Add('left join (select * from yangxiaojie where khdm like ''%'+ck+'%'' and spdm like ''%'+hh+'%'') as b');
chaxun1.SQL.Add('on shangpin.spdm=b.spdm where shangpin.spdm like ''%'+hh+'%''');
chaxun1.Close;
chaxun1.Open;
end;会不会是因为edit6 没法赋值给ck的原因?
if _cxx.Text='仓库代码' then
begin
chaxun2.Close;
chaxun2.SQL.Clear;
chaxun2.SQL.add('select ckdm as 仓库代码,ckmc as 仓库名称 from cangku ');
chaxun2.SQL.Add('where ckdm like '''+'%'+hh+'%'+'''') ;
chaxun2.Open;
end else
begin
chaxun2.Close;
chaxun2.SQL.Clear;
chaxun2.SQL.add('select ckdm as 仓库代码,ckmc as 仓库名称 from cangku');
chaxun2.SQL.Add('where ckmc like '''+'%'+hh+'%'+'''') ;
chaxun2.Open;
end;
edit6有没有内容一看就知道了啊
chaxun1.SQL.Close;
chaxun1.SQL.Clear;
chaxun1.SQL.Add('select shangpin.spdm as 商品代码,sj1 as 原价,je5 as 现价 from shangpin');
chaxun1.SQL.Add('select * from yangxiaojie);
chaxun1.SQL.Add('where khdm like ''%'+ck+'%'' );
chaxun1.SQL.Add('and spdm like ''%'+hh+'%'');
chaxun1.SQL.Add('on shangpin.spdm=b.spdm where shangpin.spdm like ''%'+hh+'%''');
chaxun1.Open;
还有这里:if ck='' then
begin
application.MessageBox('请输入仓库代码!','错误',mb_ok);
edit6.SetFocus;
end else
begin
chaxun1.Close;//先在这里关闭
chaxun.SQL.Clear;
chaxun1.SQL.Add('select shangpin.spdm as 商品代码,sj1 as 原价,je5 as 现价 from shangpin');
chaxun1.SQL.Add('left join (select * from yangxiaojie where khdm like ''%'+ck+'%'' and spdm like ''%'+hh+'%'') as b');
chaxun1.SQL.Add('on shangpin.spdm=b.spdm where shangpin.spdm like ''%'+hh+'%''');
//chaxun1.Close;
chaxun1.Open;
end; 代码太多了 看得有点晕了。最好能按先后顺序整理一下。这样大家看起来也很容易能理解了。
建议还是打断点调试一下吧。
每一步的值有没有取到都可以看到的。