Page 1 of 1
JSON data source relation
Posted: Mon Dec 07, 2020 8:33 am
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
Re: JSON data source relation
Posted: Tue Dec 08, 2020 7:40 am
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.
Re: JSON data source relation
Posted: Wed Dec 09, 2020 2:05 am
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
Re: JSON data source relation
Posted: Wed Dec 09, 2020 7:47 am
by Lech Kulikowski
Hello,
Please send us a sample that reproduces the issue for analysis.
Thank you.
Re: JSON data source relation
Posted: Wed Dec 09, 2020 9:05 am
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
Re: JSON data source relation
Posted: Thu Dec 10, 2020 10:15 pm
by Lech Kulikowski
Hello,
That is correct. In your code, you should add all columns also.
Thank you.
Re: JSON data source relation
Posted: Fri Dec 11, 2020 7:10 am
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
Re: JSON data source relation
Posted: Tue Dec 15, 2020 8:02 am
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.