firedac大师 - 细节关系不起作用

时间:2016-04-20 07:09:33

标签: master-detail firedac c++builder-xe7

数据库表的第一个定义:

CREATE TABLE UNCERTAINTY
(
  ID Integer NOT NULL,
  NAME Varchar(240) CHARACTER SET NONE NOT NULL,
  CONSTRAINT PK_UNCERTAINTY PRIMARY KEY (ID),
  UNIQUE (NAME)
);

CREATE TABLE UNCERTAINTYDETAIL
(
  ID Integer NOT NULL,
  UNCERTAINTY_ID Integer NOT NULL,
  MEASTYPE Varchar(255) CHARACTER SET NONE,
  CONDITION Varchar(255) CHARACTER SET NONE,
  POWERFACTOR Double precision,
  LOADTYPE Varchar(255) CHARACTER SET NONE,
  UNCERTAINTY Double precision,
  CONSTRAINT PK_UNCERTAINTYDETAIL PRIMARY KEY (ID)
);

ALTER TABLE UNCERTAINTYDETAIL ADD CONSTRAINT FK_UNCERTAINTY_UNCERTAINTYDETAI
  FOREIGN KEY (UNCERTAINTY_ID) REFERENCES UNCERTAINTY (ID) ON DELETE CASCADE;

现在在dfm文件中定义我的数据源和查询:

object FDQuery1: TFDQuery
  Connection = Connection1
  SQL.Strings = (
    'select * from UNCERTAINTY'
    'order by NAME')
  Left = 125
  Top = 239    
end
object FDQuery2: TFDQuery
  MasterSource = DataSource1
  MasterFields = 'ID'
  Connection = Connection1
  SQL.Strings = (
    'select * from UNCERTAINTYDETAIL'
    'where UNCERTAINTY_ID=:param1'
    'order by ID')
  Left = 456
  Top = 224
  ParamData = <
    item
      Name = 'PARAM1'
      ParamType = ptInput
    end>
end
object DataSource1: TDataSource
  DataSet = FDQuery1
  Left = 53
  Top = 239
end
object DataSource2: TDataSource
  DataSet = FDQuery2
  Left = 392
  Top = 224
end

两个数据源都连接到db网格。

在FormShow事件中,我调用以下方法:

FDQuery1->Open();
FDQuery2->Open();

主网格正确显示存储在表UNCERTAINTY中的所有项目,但详细网格始终为空。为什么?

1 个答案:

答案 0 :(得分:0)

详细查询的参数应与MasterFields匹配。因此,将FDQuery2的param1更改为ID以匹配值MasterFields。