问题:1跟2表了关联
我用了两种方法,2表里面的数据结构,只有二个值跟1表有关联,一个是商品编号,一个是商品名称;
1。商品编号是由1表的bz+lb 组成(如,海尔是10[二级分类],电视机是10[一级分类],组成就是1010,后面的00N,是数据自动累加上去了,变成了2表里面的商品编号)
procedure Tspxx.SpeedButton2Click(Sender: TObject);
begin
try
if (adoquery1.Active=false) or (adoquery1.RecordCount=0) then
begin
messagebox(handle,'没有商品记录!','系统提示',mb_iconwarning+mb_ok);
abort;
adoquery2.Close;
end
else
begin
adoquery4.Close;
adoquery4.SQL.Clear;
adoquery4.SQL.Add('select * from splb where lb like ''%'+edit1.Text+'%''');
adoquery4.Open;
if adoquery4.RecordCount=0 then
begin
messagebox(handle,'没有商品记录!','系统提示',mb_iconwarning+mb_ok);
abort;
end
else
begin
RMReport1 := TRMReport.Create(Self);
RMReport1.LoadFromFile('商品信息汇总表.rmf');
RMReport1.PrepareReport;
RMReport1.ShowReport;
end;
end;
finally
RMReport1.Free;
end;
end;
这种方法效率太低下了,因为是模糊查询lb表,这样就造成很多了不需要了数据,只有你edit1.text的数据精确到跟商品编号差不多位数了时候才是真正了数据。
2.商品名称由1表的bb+bb 组成(如,海尔是10[二级分类],电视机是10[一级分类],组成就是:海尔电视机,而这个商品名称是固定了,
而这个商品名称我必须先在查询之前,先取得商品名称 我用label2,label3代表 品牌跟商品名称
procedure Tspxx.RzTreeView1Change(Sender: TObject; Node: TTreeNode);
begin
Edit1.Text :=TLabel(Node.data).Caption;
if (length(edit1.text)=2) then//表示这个数值是2位(类别为2位数字组成,品牌为4位数字组成)
begin
adoquery4.Close;
adoquery4.SQL.Clear;
adoquery4.SQL.Add('select * from splb where lb=a');
adoquery4.Parameters.ParamByName('a').Value:=edit1.Text;
adoquery4.Open;
label2.Caption:=adoquery4.fieldByName('bb').AsString;
label3.Caption:='';
END
else
begin
adoquery4.Close;
adoquery4.SQL.Clear;
adoquery4.SQL.Add('select * from splb where lb=a');
adoquery4.Parameters.ParamByName('a').Value:=edit1.Text;
adoquery4.Open;
label3.Caption:=adoquery4.fieldByName('bb').AsString+label2.Caption;
label2.Caption:='';
end;
//adoquery1.Close;
//adoquery1.SQL.Clear;
// adoquery1.SQL.Add('select * from spxx where 商品编号 like '''+edit1.text+'%''');
// adoquery1.Open;
// adoquery3.Active:=false;
end;
这样做成了数据倒是精确了,但是如果要打印全部品牌,就无法显示
http://hi.csdn.net/attachment/201110/25/3022106_1319507689iiLx.jpg