在C#中报告FastReport动态替换数据源 [英] Dynamic replacement of a source of data in report FastReport in C #

查看:2168
本文介绍了在C#中报告FastReport动态替换数据源的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用从数据库到DataSet的表格动态更改报表FastReport中的数据源?

有一个从头开始动态创建报表的示例。但这自然需要处理所有字段。

使用数据库中的源可以直观地创建报告文件。然后将源更改为DataSet。

试试这个:

How to dynamically change the data source in a report FastReport with tables from a database to a DataSet?
There is an example of dynamically creating a report from scratch. But this naturally requires the prescribing of all fields.
Easier to visually create report file with the source from the database. And then change the source to the DataSet.
Try this:

Report report = new Report();
	report.Load(ss);							//I load a file of the report
        report.Dictionary.Clear();						//I delete an old source of data
        report.Dictionary.RegisterData(ds.Tables[nTab], имя таблицы, true); 	//I register new
        report.RegisterData(ds);
        // add report page
        ReportPage page = new ReportPage();
        report.Pages.Add(page);
        page.CreateUniqueName();

        // create title band
        DataBand dataBand = new DataBand();
        page.Bands.Clear();
        page.Bands.Add(dataBand);
        dataBand.CreateUniqueName();							
        dataBand.DataSource = report.GetDataSource(имя таблицы);		//I set the table for
 
        dataBand.Height = Units.Centimeters * 0.5f;
        report.Show();







只显示一行。




Displays only one row.

推荐答案

如果FastReport是一个库,则需要询问它们如何使用它。
If FastReport is a library, you need to ask them how to use it.


数据库未连接到数据源。添加最后一行以连接数据源和数据源:

The databand is not connected to a datasource. Add last line to connect databand to datasource:
report.Load(ss);							
report.Dictionary.Clear();						
report.Dictionary.RegisterData(ds.Tables[nTab], имя таблицы, true); 	
report.RegisterData(ds);
((DataBand)report.FindObject("Data1")).DataSource = report.Dictionary.DataSources[0];





Data1是数据和名称你的报告。



"Data1" is databand name of your report.


这篇关于在C#中报告FastReport动态替换数据源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆