Connecting Data
Information |
Since dashboards and reports use the same unified template format - MRT, methods for loading the template and working with data, the word “report” will be used in the documentation text.
|
Data for rendering a report can be connected in various ways. The easiest way is to store connection settings in the report template. Also, data can be connected from the code. You can do this before assigning the report to the viewer.
Default.aspx |
... <cc1:StiWebViewer ID="StiWebViewer1" runat="server"> </cc1:StiWebViewer> ... |
Default.aspx.cs |
... protected void Page_Load(object sender, EventArgs e) { DataSet ds = new DataSet(); ds.ReadXml(Server.MapPath("Reports/Demo.xml"));
StiReport report = new StiReport(); report.Load(Server.MapPath("Reports/TwoSimpleLists.mrt")); report.Dictionary.Databases.Clear(); report.RegData("Demo", ds);
StiWebViewer1.Report = report; } ... |
To connect report data, you can use the special OnGetReportData event, which will be called before the report is rendered.
Default.aspx |
... <cc1:StiWebViewer ID="StiWebViewer1" runat="server" OnGetReportData="StiWebViewer1_GetReportData"> </cc1:StiWebViewer> ... |
Default.aspx.cs |
... protected void StiWebViewer1_GetReportData(object sender, StiReportDataEventArgs e) { DataSet dataSet = new DataSet(); dataSet.ReadXml(Server.MapPath("Reports/Demo.xml")); e.Report.RegData(dataSet); } ... |
SQL data sources
The connection parameters to the SQL data source and any other ones can be stored in the report template. Suppose you want to set the connection parameters from the code before rendering the report (for example, for security reasons or depending on the authorized user). In that case, you can use the example below.
Also, for SQL data sources used in the report, you can specify the Query Timeout in seconds. The value of this property is stored in the report template for each SQL connection separately.
Below is an example of code that you may use to change the connection string for MS SQL, adjust the query, set the query timeout for the already created connection and data sources in the report.
You can also use data for designing reports and dashboards obtained from OData storage. In this case, you can do the authorization using a username, user password, or token. Authorization parameters are specified in the connection string to the OData storage using the ";" separator.
The table below shows the connection string templates for different types of data sources.
|
Data from XML, JSON, Excel files
Connecting to XML and JSON data sources can be stored in the report template. If you want to specify data files from the code, you can use the example below.
|