ListBox1.Items.Clear; with AdoQuery1 do begin Close; SQL.Clear; SQL.Add('select xName from Table1 where ...'); Open; if not IsEmpty then while not eof do begin ListBox1.Items.Add(FieldByName('xName').AsString); Next; end; end;
如果楼主的数据库没有特殊类型的字段,上面的应该可以了。 至于判断listbox中N行数据中有没有一行包含str字符串?? var str:string; i:integer; begin i:=0; str:='ice'; with ListBox1 do begin while i<Items.Count do begin if AnsiContainsStr(ListBox1.Items.Strings[i], str) then ShowMessage('第'+inttostr(i+1)+'行 包含str字符串!'); i:=i+1; end; end; end;这样试试
ListBox1.Items.Clear; with AdoQuery1 do begin Close; SQL.Clear; SQL.Add('select xName from Table1 where ...'); Open; if not IsEmpty then while not eof do begin ListBox1.Items.Add(FieldByName('xName').AsString); Next; end; end;
如果用ListBox的话,只有写代码了..也就几行吧.
with AdoQuery1 do
begin
Close;
SQL.Clear;
SQL.Add('select xName from Table1 where ...');
Open;
if not IsEmpty then
while not eof do
begin
ListBox1.Items.Add(FieldByName('xName').AsString);
Next;
end;
end;
至于判断listbox中N行数据中有没有一行包含str字符串??
var
str:string;
i:integer;
begin
i:=0;
str:='ice';
with ListBox1 do
begin
while i<Items.Count do
begin
if AnsiContainsStr(ListBox1.Items.Strings[i], str) then
ShowMessage('第'+inttostr(i+1)+'行 包含str字符串!');
i:=i+1;
end;
end;
end;这样试试
with AdoQuery1 do
begin
Close;
SQL.Clear;
SQL.Add('select xName from Table1 where ...');
Open;
if not IsEmpty then
while not eof do
begin
ListBox1.Items.Add(FieldByName('xName').AsString);
Next;
end;
end;