ActiveReports 9 Practical Tutorials (2): Preparing the data source (at design time, at run time)

Source: Internet
Author: User

Original: ActiveReports 9 Practical Tutorials (2): Preparing the data source (at design time, at run time)

In the ActiveReports 9 practical Tutorial (1): Hands-on Environment Visual Studio 2013 Community Edition, we have built a ActiveReports 9 development environment with Visual Studio 2013, and completed an RDL report for Hello World. In this article, we configure the data source for the report in combat, do report Development Report to know that the data source in the report is divided into the timing data source and the runtime data source. How to understand it?

These 2 types of data sources, the table structure is the same, the use of different:

1 Design-time data source for the development of internal, report team configuration, test reports.

2 runtime data source, used to run the reporting system at the local site after the system has been cut, such as modifying the string of the linked database.

From the above 2 points, it can be seen that the design-time data source run a wide range: Configure the report, test, run the report. While the runtime database switches the database link string to seamlessly implement the data source in the user site deployment, relatively easy.

The following uses the Nwind_chs.mdb data source to carry on the actual combat (AR9 after installs, the own data source? C:\Users\rogerwang\Documents\ComponentOne samples\activereports 9\data\nwind.mdb).

Design-time data sources

From View - Other Windows - Report Explorer V9, and then double-click the RDLX file based on the RDLREPORT1.RDLX file that is said.

Right-click to Add a data source

In the newly created data source DataSource1, right-click to add the DataSet.

There are 2 ways to add data in the added dataset that pops up.

Method one: Write SQL directly. This method is suitable for programmers, SQL than strong people, high efficiency.

Method Two: By AR9 the newly provided VQD (visual Query Designer). This method is suitable for the product manager, the demand analyst and so on the technology scrutiny person, is flexible.

Here's the point. Method Two: VQD.

The Visual Query Designer (VQD) contains the following key features:

    • Filtering data
    • Working with custom expressions
    • Select a field from the database
    • Grouping and aggregate functions
    • Use inner connection, left outer connection and right outer connection
    • Set aliases for selected fields and data tables
    • Data sorting and more features

Generated SQL statement:

Select Products.*, categories.* from products inner joins Categories on Products.CategoryID = Categories.CategoryID

If you drag description, ProductID to the report, preview the results:

At this point, the completion of the runtime data source Additions, AR provides the configuration of data source features, very flexible and convenient, can effectively improve the efficiency of report development.

Run-time data source

The data sources that we configure at design time, if you want to migrate to the user site, you need to be able to dynamically modify the data source to fit the user's data source environment.

Data source switching via code (note: Database table structure is identical)

Private voidRun-time data Source Zone report Toolstripmenuitem_click (Objectsender, EventArgs e) {Sectionreport_datasource_runtime SReport1=NewSectionreport_datasource_runtime (); Sreport1.datasource=Getdatasource ();        Sreport1.run (); Viewer1. Document=sreport1.document; }    PrivateDataTable Getdatasource () {DataTable dt=NewDataTable (); Dt. Columns.Add ("Product number"); Dt. Columns.Add ("Product Name"); Dt. Columns.Add ("Unit Price"); Dt. Columns.Add ("Library Stock"); Dt. Rows.Add ("A10002","Apple", -, -); Dt. Rows.Add ("A15681","Banana", -, -); Dt. Rows.Add ("A15681","Pineapple", -, -); returnDT; }

To set the data source at run time through the DataSource property

Private voidRun-Time Data source page report Toolstripmenuitem_click (Objectsender, EventArgs e) {GrapeCity.ActiveReports.PageReport PReport1=NewGrapeCity.ActiveReports.PageReport (NewSystem.IO.FileInfo ("PAGEREPORT_DATASOURCE_RUNTIME.RDLX")); Viewer1.                Loaddocument (preport1.document); }    Private voidForm1_Load (Objectsender, EventArgs e) {Viewer1. Locatedatasource+=NewGrapeCity.ActiveReports.LocateDataSourceEventHandler (Viewer1_locatedatasource); }    voidViewer1_locatedatasource (Objectsender, GrapeCity.ActiveReports.LocateDataSourceEventArgs args) {        if(args. DataSourceName = ="DataSource1")        {            if(args. DatasetName = ="DataSet1") {args. Data=Getdatasource (); }        }    }    PrivateDataTable Getdatasource () {DataTable dt=NewDataTable (); Dt. Columns.Add ("Product number"); Dt. Columns.Add ("Product Name"); Dt. Columns.Add ("Unit Price"); Dt. Columns.Add ("Library Stock"); Dt. Rows.Add ("A10002","Apple", -, -); Dt. Rows.Add ("A15681","Banana", -, -); Dt. Rows.Add ("A15681","Pineapple", -, -); returnDT; }

Loads the data source through the Locatedatasource event at run time.

Finally, by the way: ActiveReport can interact with a variety of data sources, including OLE DB, SQL, xml,oracle, Sybase, Informix, SQL Server, and more.

Refer to the Official blog:

    • ActiveReports report Data Source: Design-time data source
    • ActiveReports report Data Source: Run-time data source
    • "ActiveReports" uses rest Web service data
    • AR 7 binding Data Source mode
    • Bind Oracle Database to ActiveReport

ActiveReports 9 Practical Tutorials (2): Preparing the data source (at design time, at run time)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.