在 C# 中生成的 Stimulsoft 报告中未设置数据源
Data source is not set in report of Stimulsoft generated in C#
使用 C# + ASP.Net,我写了这段代码:
StiReport report = StiReport.CreateNewReport();
try
{
report.Load(@"D:\Report.mrt");
string Con = "Server=1.2.3.4;Persist Security Info=False;User ID=test;Password=test;MultipleActiveResultSets=False;Encrypt=True;TrustServerCertificate=True;";
foreach (var item in x)
{
report.Dictionary.Databases.Clear();
report.Dictionary.Databases.Add(new Stimulsoft.Report.Dictionary.StiSqlDatabase("Connection", "Server=itc-hisreport;Persist Security Info=False;User ID=mumsadmin;Password=mUm$@d m(n52;MultipleActiveResultSets=False;Encrypt=True;TrustServerCertificate=True;")) ;
using (SqlConnection connection = new SqlConnection(Con))
{
SqlCommand myCommand = new SqlCommand(item.DataSource, connection);
SqlDataAdapter dataAdapter = new SqlDataAdapter(myCommand);
DataSet dataSet = new DataSet("DataBase");
dataAdapter.Fill(dataSet);
report.RegData(dataSet);
((Stimulsoft.Report.Dictionary.StiSqlDatabase)(report.Dictionary.Databases[0])).ConnectionString = Con;
report.Render(false);
}
}
}
catch (Exception ex)
{
//return (new BaseResult() { Message = ex.Message, Succseed = false });
}
我有一个没有任何数据源的空白 .mrt。这部分渲染完成后,数据源没有设置。你能指导我如何设置这个文件的连接吗?
此致
添加:
report.Dictionary.Synchronize();
RegData函数解决了我的问题!
使用 C# + ASP.Net,我写了这段代码:
StiReport report = StiReport.CreateNewReport();
try
{
report.Load(@"D:\Report.mrt");
string Con = "Server=1.2.3.4;Persist Security Info=False;User ID=test;Password=test;MultipleActiveResultSets=False;Encrypt=True;TrustServerCertificate=True;";
foreach (var item in x)
{
report.Dictionary.Databases.Clear();
report.Dictionary.Databases.Add(new Stimulsoft.Report.Dictionary.StiSqlDatabase("Connection", "Server=itc-hisreport;Persist Security Info=False;User ID=mumsadmin;Password=mUm$@d m(n52;MultipleActiveResultSets=False;Encrypt=True;TrustServerCertificate=True;")) ;
using (SqlConnection connection = new SqlConnection(Con))
{
SqlCommand myCommand = new SqlCommand(item.DataSource, connection);
SqlDataAdapter dataAdapter = new SqlDataAdapter(myCommand);
DataSet dataSet = new DataSet("DataBase");
dataAdapter.Fill(dataSet);
report.RegData(dataSet);
((Stimulsoft.Report.Dictionary.StiSqlDatabase)(report.Dictionary.Databases[0])).ConnectionString = Con;
report.Render(false);
}
}
}
catch (Exception ex)
{
//return (new BaseResult() { Message = ex.Message, Succseed = false });
}
我有一个没有任何数据源的空白 .mrt。这部分渲染完成后,数据源没有设置。你能指导我如何设置这个文件的连接吗?
此致
添加:
report.Dictionary.Synchronize();
RegData函数解决了我的问题!