尧图网站设计 尧图网站设计YAOTU DESIGN
ARTICLE DETAIL

资讯详情

深耕网站设计与一线实操的经验洞察。

FastReport传递参数在报表段进行数据查询(报表参数查询)

FastReport传递参数在报表段进行数据查询(报表参数查询) 在使用FastReport时有时需要根据参数读取一部分数据这里我们使用fastReport的参数查询进行实验。1.创建报表数据连接和创建参数2.修改数据连接sql加上查询条件带上参数3.在下一步时识别参数如果没有识别到则进行添加参数将上一步sql中的参数写上不要带注意字段类型和长度。在表达式中写[userName] 这里的方括号代表全局参数这个参数由c#段进行传递过来。4. 对应的程序代码这里完全采用报表段进行数据获取因此取消了代码中的数据查询。using System; using System.Collections.Generic; using System.ComponentModel; using System.Windows.Forms; using FastReport; namespace FT.CustomFormPages.Finance { public partial class FmBuyAndSellStoreDayReportPrint : Form { private int id; private string reportDate; private string comNames; private Report report; public FmBuyAndSellStoreDayReportPrint(string reportDateP, string comNamesP) { InitializeComponent(); reportDate reportDateP; comNames comNamesP; initReport(); } private void initReport() { //DataSet ds1 null; string conStr BaseSystemInfo.ConnectionString; string userName UserHelper.UserName; report new FastReport.Report(); try { string filename BaseSystemInfo.ReportTemplatePath \A.frx; report.Load(filename); report.Preview this.previewControl1; report.SetParameterValue(conn, conStr); report.SetParameterValue(reportDate, reportDate); report.SetParameterValue(comNames, comNames); report.SetParameterValue(userName, userName); report.Prepare(); report.ShowPrepared(); } catch (Exception err) { //记录完整异常堆栈方便排查40连接错误、报表脚本报错 FileLogClass.WriteLogFile(异常错误 err.Message \r\n堆栈: err.StackTrace); } } private void FmBuyAndSellStoreDayReportPrint_FormClosed(object sender, FormClosedEventArgs e) { if (report ! null) { report.Dispose(); report null; } } } }
返回列表