Click here to Skip to main content
15,071,262 members
Please Sign up or sign in to vote.
1.00/5 (3 votes)
See more:
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.
Posted
Updated 2-Apr-19 22:14pm
v4
Comments
CPallini 27-Jan-11 6:31am
   
Please take care of translating your text to English.
m@dhu 27-Jan-11 6:35am
   
Translated to english.
CPallini 27-Jan-11 6:39am
   
Very good (it's a pity I cannot vote you for that!). Could you please translate the title too (I may just guess it...).
m@dhu 27-Jan-11 6:57am
   
Thanks sir. Updated.
[no name] 27-Jul-17 3:31am
   
If you clear all dictionary...you lost all data from report (totals, params, functions...).

The databand is not connected to a datasource. Add last line to connect databand to datasource:
C#
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" is databand name of your report.
   
v3
If FastReport is a library, you need to ask them how to use it.
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900