Select datasource

dannidanni Denmark
edited 2:12AM in FastReport .NET
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

Comments

  • edited 2:12AM
    Hello,

    do
    report.GetDataSource("your_ds").Enabled = true;
    
    after RegisterData call.
  • dannidanni Denmark
    edited 2:12AM
    Thank you :-)
  • jbgjbg
    edited July 2009
    Hello! I have a question too:


    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 >
  • edited 2:12AM
    Hello,

    The solution is correct. But in order to use it, you need to have a Data band named "Data1" in your report.
  • jbgjbg
    edited 2:12AM
    Hmm. Thanks for the advice, forgot to take a look at the naming. But, there indeed is a databand named Data1 in the design.it seems that having it inside Group Header/Footer somehow throws an exception. If i move the databand outside of all groups, it works. But i need those groups. Any idea?
  • edited July 2009
    I checked it with groups, it works well.

    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.
  • jbgjbg
    edited 2:12AM
    Thanks for the quick answer.

    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.
  • edited 2:12AM
    Sorry, I can't reproduce the error with DataFromDataSet, could you provide step-by-step instructions?
  • jbgjbg
    edited 2:12AM
    Okay, ill try, im using FasReport v1.1.51.0:
    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.

  • edited July 2009
    It's because you did not set the group condition for the group header band. Once you set it to say [Employees.ID] the report will be ok.
  • jbgjbg
    edited 2:12AM
    Thank you very much, was a foolish mistake, works now.
    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]

Leave a Comment

Rich Text Editor. To edit a paragraph's style, hit tab to get to the paragraph menu. From there you will be able to pick one style. Nothing defaults to paragraph. An inline formatting menu will show up when you select text. Hit tab to get into that menu. Some elements, such as rich link embeds, images, loading indicators, and error messages may get inserted into the editor. You may navigate to these using the arrow keys inside of the editor and delete them with the delete or backspace key.