Delphi - 表单传递参数到报表生成器

时间:2016-08-03 01:37:34

标签: delphi

如何将参数值从表单传递给Report Builder?

还是有任何错误?

报告构建器SQL:

SELECT * FROM Member Where MemberID = :MemberID

表格代码:

procedure TfmRbTest.Button1Click(Sender: TObject);
begin
  ppReport1.Template.FileName = 'Member.rtm'
  ppReport1.Template.LoadFileName;
  ppReport1.Parameters['MemberID'].Value := '000001';
  ppReport1.Print;
end;

1 个答案:

答案 0 :(得分:1)

您没有提供足够的信息以确定,但这是我的猜测。

您需要注意参数类型。您生成的SQL是

SELECT * FROM Member where MemberID = 000001

如果MemberID是文字,则需要

SELECT * FROM Member where MemberID = '000001'

您将使用以下代码生成

procedure TfmRbTest.Button1Click(Sender: TObject);
begin
  ppReport1.Template.FileName = 'Member.rtm'
  ppReport1.Template.LoadFileName;
  ppReport1.Parameters['MemberID'].Value := '''000001''';
  ppReport1.Print;
end;

或者我认为您可以保留代码并将查询更改为

SELECT * FROM Member where MemberID = ':MemberID'

但我不是百分之百。