Connecting Data
Data for report rendering can be connected in various ways. The easiest way is to keep connection settings in a report template. In addition, data can be connected from a code. You can do it before a report is assigned to the viewer.
Index.razor |
@using Stimulsoft.Report @using Stimulsoft.Report.Blazor @using Stimulsoft.Report.Web
<StiBlazorViewer Report="@Report" />
@code { //Report object to use in viewer private StiReport Report;
protected override void OnInitialized() { base.OnInitialized();
//Load new data from XML file var data = new System.Data.DataSet(); data.ReadXml("Data/Demo.xml");
//Create and load report template var report = new StiReport(); report.Load("Reports/TwoSimpleLists.mrt"); report.Dictionary.Databases.Clear(); report.RegData("Demo", data);
//Assing report object to viewer Report = report; } } |
Information |
At this moment, the SQL data resources are supported only for Blazor Server components.
|
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 using a 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
You can keep connections to the XML and the JSON data resources in a report template. If you need to specify data files from a code, you can use the following example.
|