c# 如何以编程方式过滤 stimulsoft 报告?

c# how to filter stimulsoft report programatically?

我正在开发一个 C# 项目。我使用 stimulsoft 在我的项目中创建和显示报告。 我在 stimulsoft 软件中设计我的报告并将我的报告文件保存在 ...\bin\debug\reports 路径中。

这是我的报表设计:

enter image description here

此报告显示系统用户。

现在,我想用 C# 过滤我的报告。我如何发送公式来过滤我的报告结果?

这是我用来显示报告的代码:

    StiReport report = new StiReport();
        report.Load(System.AppDomain.CurrentDomain.BaseDirectory + "\reports\userinfo.mrt");
        report.Show();

这个例子部分取自他们的文件Stimulsoft_NET_FAQ.pdf

首先在用于从数据源中提取数据的查询中创建一个参数

SELECT * from Users WHERE userID  =  @userID

那么你在调用Show之前传递这个参数

StiReport report = new StiReport();
report.Load(.... your file....));
report.Dictionary.Databases.Clear();
StiSqlDatabase db = new StiSqlDatabase("the_name_of_datasource", "the connection string");
report.Dictionary.Databases.Add(db);
report.CacheAllData = true;
report.Dictionary.Synchronize();
report.Compile();
// Finally set the parameter
report["@userID"] = 1; // <= value to search for....
report.Show(true);

此示例适用于 Sql 服务器数据库后端。如果您有不同的数据库引擎,请使用可用的 StiXXXXXXDatabase

中的一种