Delphi - DBGrid 不显示 ADO 表的内容
Posted
技术标签:
【中文标题】Delphi - DBGrid 不显示 ADO 表的内容【英文标题】:Delphi - DBGrid doesn't display contents of ADO Table 【发布时间】:2021-02-04 06:57:20 【问题描述】:所以我尝试在运行时将所有 ADO 表加载到它们各自的 DBGrid 中。我没有收到任何错误,但网格中没有显示任何内容?我在这里做错了什么?
我正在使用的代码:
procedure TfrmEntry.FormActivate(Sender: TObject);
begin
GridSetupContainer;
end;
procedure TfrmEntry.GridSetupContainer;
begin
with dmArchive do
begin
GridSetup(dbgA16,dsr1660);
GridSetup(dbgA2P1,dsrTwoPointOne);
GridSetup(dbgAXKarts,dsrXKarts);
GridSetup(dbgAHM,dsrHeavyMetals);
GridSetup(dbgAHR,dsrHotrods);
GridSetup(dbgAMIDA,dsrMidA);
GridSetup(dbgAMIDB,dsrMidB);
GridSetup(dbgAMinis,dsrMinis);
GridSetup(dbgAPink,dsrPinkrods);
GridSetup(dbgASpr,dsrSprints);
GridSetup(dbgASR,dsrStockrods);
GridSetup(dbgADev,dsrDev);
GridSetup(dbgAV8,dsrV8);
GridSetup(dbgALM,dsrLateModels);
end;
with dmRacers do
begin
GridSetup(dbgR16,dsr1660);
GridSetup(dbgR2P1,dsrTwoPointOne);
GridSetup(dbgRXKarts,dsrXKarts);
GridSetup(dbgRHM,dsrHeavyMetals);
GridSetup(dbgRHR,dsrHotrods);
GridSetup(dbgRMIDA,dsrMidA);
GridSetup(dbgRMIDB,dsrMidB);
GridSetup(dbgRMini,dsrMinis);
GridSetup(dbgRPink,dsrPinkrods);
GridSetup(dbgRSP,dsrSprints);
GridSetup(dbgRSR,dsrStockrods);
GridSetup(dbgRDev,dsrDev);
GridSetup(dbgRV8,dsrV8);
GridSetup(dbgRLM,dsrLateModels);
end;
end;
procedure TfrmEntry.GridSetup(grid: TDBGrid; source: TDataSource);
begin
grid.DataSource:=source;
end;
提前感谢您的帮助!
亲切的问候 PrimeBeat
【问题讨论】:
您已经展示了将数据库网格链接到数据源的代码。但是这些数据源是否与数据集相关联?如何激活数据集? 【参考方案1】:试试这个:
procedure TfrmEntry.GridSetup(grid: TDBGrid; source: TDataSource);
begin
grid.DataSource:=source;
source.dataset.open; //this line!!! perhaps you don't open the table!, edited has sugested by Peter Wolf
end;
【讨论】:
以上是关于Delphi - DBGrid 不显示 ADO 表的内容的主要内容,如果未能解决你的问题,请参考以下文章