先用query查询取出数据后,开始写入.试试下面的函数 procedure SetGridInfo(StrGrid:TStringGrid;sQuery:TAdoQuery); var i,j:integer; begin StrGrid.RowCount:=2; i:=1; while not sQuery.eof do begin StrGrid.Cells[0,i]:=inttostr(i); for j:=1 to sQuery.FieldCount do begin StrGrid.Cells[j,i]:=sQuery.Fields[j-1].AsString; end; i:=i+1; StrGrid.RowCount:=StrGrid.RowCount+1; sQuery.Next; end; end;
procedure SetGridInfo(StrGrid:TStringGrid;sQuery:TAdoQuery);
var
i,j:integer;
begin
StrGrid.RowCount:=2;
i:=1;
while not sQuery.eof do
begin
StrGrid.Cells[0,i]:=inttostr(i);
for j:=1 to sQuery.FieldCount do
begin
StrGrid.Cells[j,i]:=sQuery.Fields[j-1].AsString;
end;
i:=i+1;
StrGrid.RowCount:=StrGrid.RowCount+1;
sQuery.Next;
end;
end;
总体思路是两重循环,每个cell显示一个数据
代码基本就如楼上说的,具体自己调整下