Select datasource
danni
Denmark
Hi
How do I select datasources in the code after Report.RegisterData ?
The thing is I want to strip the designer so my users cannot select a datsource themselves. But I have preselected one for them in my code.
Thank you
How do I select datasources in the code after Report.RegisterData ?
The thing is I want to strip the designer so my users cannot select a datsource themselves. But I have preselected one for them in my code.
Thank you
Comments
do after RegisterData call.
Lets say i have a DataSet with a table "Mail" in it.
Mail has columns : Mail.Number Mail.address Mail.PoBox
First I design the report layout in Fastreport designer with the use of
[Mail.Number] [Mail.address] [Mail.PoBox] to display data (i dont have a datasource set in the designer), and save it to a frx file.
In the code i do :
report1.Load("layout.frx");
report1.RegisterData(data.Tables[0],"Mail");
report1.GetDataSource("Mail").Enabled = true;
report1.Show...
And the report prints out empty with no data in it.
Have i missed something in the designer ?
It worked, when i used datasources in the designer with connection strings and queries, but that is not the way i need it to be. I need the Designer to read from a DataSet specified in the code.
Any help?, Thanks
EDIT:
found a similar question here : http://www.fast-report.com/en/forum/?p=/discussion/5254
But the solution :
DataBand db1 = (DataBand)report.FindObject("Data1");
db1.DataSource = report.GetDataSource("Mail");
now throws a "Object reference not set to an instance of an object." error
The solution is correct. But in order to use it, you need to have a Data band named "Data1" in your report.
If you need to use an application dataset to design a report, you may:
- Use technique described in the programmer's manual (Working with Windows.Forms/Using the Report component in Visual Studio). You need typed DataSet in this case.
-or-
- Call the report designer from your application to create a new report. This technique is used in Demo.exe - in fact, all demo reports are created in such way.
So its not possible to do it with the solution i found ? To replicate the problem : Using your demo \FastReport.Net Demo\Demos\C#\DataFromDataSet, the demo works as long as i dont insert a group around the databand "Data1" in the report.frx from the demo. It then throws a "Failed to compare two elements in the array." exception.
I'll try to use Typed datasets only when i run out of options.
i :
- open the DataFromDataSet project with VS2008, compile and run it. I click the "Run existing report" button, it works.
- open the FastReport.Net Demo/Demo.exe and click " Run the designer" where i open the report.frx from the DataFromDataSet directory.
- click on Configure bands , select Data:Employees, click on Add -> Group Header. Save.
- now when clicking Run existing report again, it throws that error.
Thanks for your time.
would be great to put
DataBand db1 = (DataBand)report.FindObject("Data1");
db1.DataSource = report.GetDataSource("Mail");
In the documentation as an example, may save some time for a newb like me [img]style_emoticons/<#EMO_DIR#>/smile.gif" style="vertical-align:middle" emoid=":)" border="0" alt="smile.gif" /> Thanks again,[/img]