JSON data source relation

Stimulsoft Dashboards.WEB discussion
Post Reply
jk50po
Posts: 29
Joined: Wed May 27, 2020 7:28 am

JSON data source relation

Post by jk50po »

Hi Stimulsoft team.
I need to use a JSON data source in the next report. I encountered a problem. When I established a relationship in multiple JSON data sources, an error occurred in the preview report.

Code: Select all

The parent Data Source 'root' and the Child Data Source 'root2' is not located in one DataSet and can't be used in the relation 'relation'! You can use the CacheAllData property of a report to cache this Data Source to one DataSet.
This prompt means that it can be solved by background code. Can you provide a simple example?
The version I use is Stimulsoft Dashboard Web NetCore 2020.5.1
thanks in advance
Attachments
Lech Kulikowski
Posts: 6245
Joined: Tue Mar 20, 2018 5:34 am

Re: JSON data source relation

Post by Lech Kulikowski »

Hello,

Please try to set the CacheAllData property for the report.

Or in your code load your json files in one DataSet and then register it to the report with RegData() method.

Thank you.
jk50po
Posts: 29
Joined: Wed May 27, 2020 7:28 am

Re: JSON data source relation

Post by jk50po »

Speaking of adding data sources to the code, I want to ask. The examples I found on the official website are to import or open an mrt file and then update the data source inside, but my requirement is to create a new report and How to add several data sources by default

Code: Select all

 public IActionResult GetReport(string id)
        {
            StiReport report = new StiReport();
            SqlConnection connection = new SqlConnection("Integrated Security=False;Data Source=.;Initial Catalog=database;");
            connection.Open();
            SqlDataAdapter adapter = new SqlDataAdapter();
            SqlCommand command = new SqlCommand("SELECT top 10 * FROM BudgetDataTotal", connection);
            adapter.SelectCommand = command;
            DataSet dataSet = new DataSet("ff");
            adapter.Fill(dataSet, "dd");
            report.RegData("ee", dataSet);
            return StiNetCoreDesigner.GetReportResult(this, report);
        }
The above code runs without problems, but it did not help me create a good data source and data set
Lech Kulikowski
Posts: 6245
Joined: Tue Mar 20, 2018 5:34 am

Re: JSON data source relation

Post by Lech Kulikowski »

Hello,

Please send us a sample that reproduces the issue for analysis.

Thank you.
jk50po
Posts: 29
Joined: Wed May 27, 2020 7:28 am

Re: JSON data source relation

Post by jk50po »

thank you for your reply
Initialize the designer and load the generated data set by default. I have made a simple effect. At present, there is still a problem. The column cannot be automatically generated. Note: The data source is MSSQL
As shown in the figure, there is no problem with the data connection and data source, but no column is generated
The code is very simple. This is an empty designer page and no report file is opened.

Code: Select all

public IActionResult GetReport(string id)
        {
            StiReport report = new StiReport();
            StiSqlDatabase ssdb = new StiSqlDatabase("Test", "Integrated Security=False;Data Source=.;Initial Catalog=DataAssets;");
            report.Dictionary.Databases.Add(ssdb);
            StiSqlSource sss = new StiSqlSource("Test", "dd", "dd", "SELECT top 10 * FROM BudgetDataTotal", true, false, 30);
            report.Dictionary.DataSources.Add(sss);
            return StiNetCoreDesigner.GetReportResult(this, report);
        }
I know that StiSqlSource has a SynchronizeColumns method, but it has no effect
Attachments
20201209170137.png
20201209170137.png (77.69 KiB) Viewed 4099 times
Lech Kulikowski
Posts: 6245
Joined: Tue Mar 20, 2018 5:34 am

Re: JSON data source relation

Post by Lech Kulikowski »

Hello,

That is correct. In your code, you should add all columns also.

Thank you.
jk50po
Posts: 29
Joined: Wed May 27, 2020 7:28 am

Re: JSON data source relation

Post by jk50po »

Thank you for your reply. I don't know how to add columns. I need to be able to get columns automatically, similar to the function of retrieve columns. Can you provide code for reference
Lech Kulikowski
Posts: 6245
Joined: Tue Mar 20, 2018 5:34 am

Re: JSON data source relation

Post by Lech Kulikowski »

Hello,

You can use the following code.
New connection string:

Code: Select all

report.Dictionary.Databases.Clear();
report.Dictionary.Databases.Add(new Stimulsoft.Report.Dictionary.StiSqlDatabase("Connection", newConnectionString));
Add DataSources:

Code: Select all

StiSqlSource DataSource1 = new StiSqlSource("Connection", "DataSource1", "DataSource1", "SELECT * FROM DataSource1", true, false);
report.Dictionary.DataSources.Add(DataSource1);
Add Columns:

Code: Select all

foreach (DataColumn col in dataTableDataSetFilledViaDataAdapter1.Columns)
 {
      DataSource1.Columns.Add(col.ColumnName, col.DataType);
 }
Thank you.
Post Reply