这是我以前写的代码,你参考一下。 listbox1.Clear; with itemlot do begin close; sql.Clear; sql.Add('select mol_itm_code,mol_lotnum from renywip where mop_opr_code in(select wws_routing from tblwipworkstd where cost_routing=:A) '); sql.Add('order by mol_itm_code,mol_lotnum'); Parameters.ParamByName('A').Value:=trim(combobox1.Text); open; end; if itemlot.RecordCount>0 then while not itemlot.Eof do begin listbox1.Items.Add(itemlot.FieldValues['mol_itm_code']+'___'+itemlot.FieldValues['mol_lotnum']); itemlot.Next; end;
listbox1.items.clear; adoquery1.close; adoquery1.connection:=adoconnection1; adoquery1.sql.clear; adoquery1.sql.add(select distinct name from tablename); adoquery1.open; while not adoquery1.eof do begin s:=adoquery1.fieldbyname('name').asstring; listbox1.items.add(s); adoquery1.next; end;
with itemlot do
begin
close;
sql.Clear;
sql.Add('select mol_itm_code,mol_lotnum from renywip where mop_opr_code in(select wws_routing from tblwipworkstd where cost_routing=:A) ');
sql.Add('order by mol_itm_code,mol_lotnum');
Parameters.ParamByName('A').Value:=trim(combobox1.Text);
open;
end;
if itemlot.RecordCount>0 then
while not itemlot.Eof do
begin
listbox1.Items.Add(itemlot.FieldValues['mol_itm_code']+'___'+itemlot.FieldValues['mol_lotnum']);
itemlot.Next;
end;
listbox1.items.clear;
adoquery1.close;
adoquery1.connection:=adoconnection1;
adoquery1.sql.clear;
adoquery1.sql.add(select distinct name from tablename);
adoquery1.open;
while not adoquery1.eof do
begin
s:=adoquery1.fieldbyname('name').asstring;
listbox1.items.add(s);
adoquery1.next;
end;