如何将数据库中我的表格数据与TStringGrid链接?
答案 0 :(得分:0)
编辑: 正如Llama所述,它不具有约束力,下面的代码仅显示字符串列表中的查询值。 请测试一下,因为我不在Delphi atm附近:
var
fCol, fLine : integer;
begin
for fCol := 0 to Query1.Fields.Count-1 do
begin
stringgrid1.Cells[fCol, 0] := Query1.Fields[fCol].DisplayLabel;
StringGrid1.ColWidths[fCol] := Query1.Fields[fCol].DisplayWidth;
end;
fLine := 1;
with Query1 do
begin
while not eof do
begin
for fCol := 0 to Fields.Count-1 do
begin
stringgrid1.cells[fCol, fLine] := Fields.Fields[fCol].asstring;
end;
inc(fLine);
next;
end;
end;
end;