Newbie question

Ok, so I've spent a fair amount of time trying to get a fairly simple Web report i.e. ASP.NET example working the way I think it should, but I still seem to be struggling.

I'm hoping someone can throw some light on which way is the best approach?

Firstly, I am slightly confused why when I create a new report from scratch, I seem to only ever end up with Data Source->Connection->Tablename setup where as all of the example reports seem to be Data Source->Tablename? Do I need to do something clever to step over the need for a "Connection"?

Bear in mind, I am coming from a Win32 Crystal Reports world where that isn't such a ridiculous concept.

Having got this, I can load the pre-defined report up into a web page and it shows me the full dataset that I defined in my report.

If I were to deploy this then presumably I would need to dynamically change the connectionstring to wherever my live DB existed? How is this done?

Failing this, I had hoped, to simply be able to RegsiterData generated from a dynamically created dataset e.g.

sqlComm := new SQLCommand;
sqlComm.CommandText := 'select * from Tablename where <some condition>';
sqlComm.Connection := dbConn;

da := new SqlDataAdapter;
da.SelectCommand := sqlComm;

FDataSet := new DataSet();
da.Fill(FDataSet);

FReport.RegisterData(FDataSet, 'Tablename');

However, although the code seems to execute correctly, I still only get the design time data, not my runtime data.

Should I be referencing the 'Tablename' or perhaps 'Connection.Tablename'?

Any thoughts gratefully received

Comments

  • edited 10:02AM
    There are two ways to print data in a webreport.

    1) You have datasource in your program. It may be SqlDataSource, AccessDataSource, ObjectDataSource etc. To use it in a report, you register the datasource.
    This way is described in the programmer's manual ("Working with ASP.NET/Using the WebReport component" chapter).

    2) You create the datasource inside a report (via the "Data/Add Data Source..." menu). You define a connection to the database, and use one or several tables from it.
    This way is described in the user's manual (http://fast-report.com/documentation/UserManFrNET-en/datasources.htm).

    If you use (2) way, you will probably want to change the connection string. It can be done in the WebReport.StartReport event:

    WebReport1.Report.Dictionary.Connections[0].ConnectionString = ".....";

  • edited 10:02AM
    AlexTZ wrote: »
    There are two ways to print data in a webreport.

    1) You have datasource in your program. It may be SqlDataSource, AccessDataSource, ObjectDataSource etc. To use it in a report, you register the datasource.
    This way is described in the programmer's manual ("Working with ASP.NET/Using the WebReport component" chapter).

    2) You create the datasource inside a report (via the "Data/Add Data Source..." menu). You define a connection to the database, and use one or several tables from it.
    This way is described in the user's manual (http://fast-report.com/documentation/UserManFrNET-en/datasources.htm).

    If you use (2) way, you will probably want to change the connection string. It can be done in the WebReport.StartReport event:

    WebReport1.Report.Dictionary.Connections[0].ConnectionString = ".....";

    Option (2) certainly makes sense and I can try this route out. How would I then limit the report to only show a sub-set of the table (equivalent of a "where" clause on the DataSource)?

    Does that mean for option (1) you need to have an actual SqlDataSource component existing on your web form to be able to design your report? What if your datasources are only ever generated dynamically in the code? Can you still design your frx file outside of VS and load it up manually?
  • edited 10:02AM
    To show a subset, you need to create a query. Please read the manual:
    http://fast-report.com/documentation/UserM...atesqlquery.htm

    What to do if you use dynamically generated data:
    1) try to use ObjectDataSource component, bind it to your data class, then use it in a report just like SqlDataSource.
    2) or, try to call the report designer in run-time. This way is harder, but you will work with "live data". To do this:
    - put the button on your webform and write the following code in its Click handler:
    {
      Report report = new Report();
      // register your data here
      report.RegisterData(.....);
    
      Thread th = new Thread(DoDesign);
      th.SetApartmentState(ApartmentState.STA);
      th.Start(report);
    }
    
    private void DoDesign(Object obj)
    {
      (obj as Report).Design();
    }
    
    - run your webapplication and click the button;
    - design a report and save it to a file;
    - remove the button from your production version;
    - to run the report, use WebReport component. You will need to register your data again, it can be done in WebReport.StartReport event:
    {
      WebReport1.Report.RegisterData(.....); // do the same as when you design a report.
    }
    
  • edited 10:02AM
    Sorry, I think I may have overcomplicated things...

    All I was asking was whether having loaded a pre-defined frx i.e.

    WebReport1.ReportFile := 'Test.frx';

    whether you could uses a differently named DataSource (potentially dynamically created)

    alt_ds := new SqlDataSource;
    alt_ds.ConnectionString := ...;
    alt_ds.SelectCommand := ...;
    ...
    WebReport1.ReportDataSources := alt_ds.Id; // Changed from, say, 'OriginalDataSource'

    rather than the hard wired DataSource that the report was designed against (assuming of course they return the same data)?

    Everytime I've tried to do this the report shows up blank, presumably because Test.frx only knows about OriginalDataSource and not alt_ds?

  • edited 10:02AM
    It's hard or even impossible. Consider using run-time designer to create a report on a dynamic data.

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.