procedure TForm1.Button1Click(Sender: TObject); var i : integer; s : string; beginwith adoquery1 do begin close; sql.clear; sql.add('select * from baseinfo '); open; while not eof do begin s := ''; for i := 0 to FieldList.Count-1 do s := s+ Fields[i].AsString; Memo1.Lines.Add(s); Next; end; end; end;
用TStrings就可以了,每一行都是一个Stringvar StrList: TStrings; begin StrList := TStringList.Create; while table.eof do begin StrList.Add(table.fieldbyname('field').asstring); table.next; end;
楼上的说得差不多了,取记录赋给string变量应该是基本的数据库操作了,假设你要取的是表t1的字段f1,类似: var sl: TStrings; begin sl := TStringList.Create; Adoquery1.SQL.Text := 'select f1 from t1'; Adoquery1.Open; while not Adoquery1.Eof do begin sl.Add(Adoquery1.FieldByName('f1').AsString); Adoquery1.Next; end; Adoquery1.Close;
var
i : integer;
s : string;
beginwith adoquery1 do
begin
close;
sql.clear;
sql.add('select * from baseinfo ');
open;
while not eof do
begin
s := '';
for i := 0 to FieldList.Count-1 do
s := s+ Fields[i].AsString; Memo1.Lines.Add(s);
Next;
end;
end;
end;
StrList: TStrings;
begin
StrList := TStringList.Create;
while table.eof do
begin
StrList.Add(table.fieldbyname('field').asstring);
table.next;
end;
var
sl: TStrings;
begin
sl := TStringList.Create;
Adoquery1.SQL.Text := 'select f1 from t1';
Adoquery1.Open;
while not Adoquery1.Eof do
begin
sl.Add(Adoquery1.FieldByName('f1').AsString);
Adoquery1.Next;
end;
Adoquery1.Close;
ShowMessage(sl.Text);
end;