FastReport.NET 2023使用DataTable报表数据源配置MsSqlDataConnection连接
FastReport.NET 2023使用DataTable报表数据源配置MsSqlDataConnection连接
报表组件版本:FastReport.NET 2023.1.8
MsSqlDataConnection 参考代码
C# 全选
private void InitDataSource(Report report, DataSet demoData)
{
//生成报表数据源
RegisteredObjects.AddConnection(typeof(MsSqlDataConnection));
MsSqlDataConnection connection = new MsSqlDataConnection();
connection.ConnectionString = _wizard.DemoDataConnectionString;
report.Dictionary.Connections.Add(connection);
//设置报表设计器的数据源
FastReport.EnvironmentSettings settings = new FastReport.EnvironmentSettings();
settings.DesignerSettings.ApplicationConnection = new System.Data.SqlClient.SqlConnection();
settings.DesignerSettings.ApplicationConnection.ConnectionString = _wizard.DemoDataConnectionString;
Config.DesignerSettings = settings.DesignerSettings;
//注册数据源
report.RegisterData(demoData.Tables[0], "M");
var ds = report.GetDataSource("M");
(report.GetDataSource("M") as TableDataSource).Enabled = true; //重要
//给DataBand(主表数据)绑定数据源
DataBand masterBand = report.FindObject("Data1") as DataBand;
masterBand.DataSource = report.GetDataSource("M"); //主表
report.Parameters.FindByName("pReportTitle").Value = $"C/S开发框架报表生成器 by {_wizard.ReportControlType}";
report.Parameters.FindByName("pPrintUser").Value = "C/S框架网(admin)";
report.Parameters.FindByName("pPrintTime").Value = DateTime.Now;
}
报表设计器查看数据源
基于 MsSqlDataConnection 数据库连接添加其他数据源
报表设计器预览报表
版权声明:本文为开发框架文库发布内容,转载请附上原文出处连接
NewDoc C/S框架网