External DataTable to Report.

Hi guys, this is my first topic.

I started to develop in FastReport.Net yesterday... and I'm having lots of problems...

I'm using VS2008 and C#.

1) I have in my WebForm one DataTable, how can I connect this data to the Report?
2) To design my report, how can I localize my DataTable (at DataSources area) to drag and drop the fields to the Data Band of the Report?

Any example is welcome.

Tks!


Comments

  • edited 2:29AM
    And more...

    My DataSource Window Select shows nothing. (picture attached)
  • edited 2:29AM
    Hello,

    WebReport component is designed to use datasources such as SqlDataSource, AccessDataSource, ObjectDataSource and similar. You can read about this in the programmer's manual, "Working with ASP.NET/Using the WebReport component". Using the DataTable component is a bit tricky. Since you don't have access to it at design time, you cannot use it as a datasource when creating a report. You may do the following:
    - put the WebReport component on the form;
    - invoke the report designer;
    - add a new datasource using the "Data|Add Data Source..." menu. Connect to your DB and choose the table which you want in your report;
    - design your report;
    - now, to replace the datasource in a report with your DataTable, create the WebReport.StartReport event handler:

    WebReport1.Report.RegisterData(myDataTable, "Name_of_the_report_datasource");

    Your DataTable must have the same structure as the table used in a report.
  • edited 2:29AM
    Dear Alex, thanks for the answer.

    I understood the way to do with DataTable but for my team it's a
    little bit unproductive to work like this.

    My data isn't in the database, it's at the WebSite Session.

    To clarify better, it's a small cadastre with 5 fields and I don't need
    to save this, just print.

    I'll try to do this by the ObjectDataSource.

    I'll keep in touching.

    Tks.
  • edited 2:29AM
    Dear Alex,

    I did the report using ObjectDataSource and it worked. (Source attached)

    I have two more doubts:

    1??) Can I delimit the Data Band to print just 5 records per page?

    2??) How the component WebReport knows wich report (*.frx) to load? Where I set this?
    I have just one report and works, but if I have two or more?
  • edited 2:29AM
    1) You can use the script to start a new page after every 5th data row:
    - click the data band;
    - go to the Properties window;
    - click Events button;
    - create AfterPrint event handler:
        private void Data1_AfterPrint(object sender, EventArgs e)
        {
          if ((Data1.RowNo % 5) == 0)
            Engine.StartNewPage();
        }
    

    2) By default, the report is stored in a webform. Read about storage in the programmer's manual "Working with ASP.NET/Storing and loading a report". The recommended way is to store the report in a file (via the ReportFile property). You may set this property in the Page.Load event handler to show the needed report.
  • edited 2:29AM
    Thanks Alex!

    I'll do more tests.
  • edited 2:29AM
    Hello,

    In my solution I have two pages, one to set data and another to report viewer, but I want to export the report directly do PDF without the viewer. Is it Possible?
  • edited 2:29AM
    Hello,

    You may use the following code:
            protected void Button1_Click(object sender, EventArgs e)
            {
                FastReport.Utils.Config.WebMode = true;
    
                using (Report report = new Report())
                {
                    report.Load("your_report.frx");
                    report.RegisterData(...);
                    report.Prepare();
    
                    // Export report to PDF stream
                    FastReport.Export.Pdf.PDFExport pdfExport = new FastReport.Export.Pdf.PDFExport();
                    using (MemoryStream strm = new MemoryStream())
                    {
                        report.Export(pdfExport, strm);
    
                        // Stream the PDF back to the client as an attachment
                        Response.ClearContent();
                        Response.ClearHeaders();
                        Response.Buffer = true;
                        Response.ContentType = "Application/PDF";
                        Response.AddHeader("Content-Disposition", "attachment;filename=report.pdf");
    
                        strm.Position = 0;
                        strm.WriteTo(Response.OutputStream);
                        Response.End();
                    }
    
                }
            }
    

    In this case, you don't need WebReport component.

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.