如何在运行时更改stimulsoft报告的连接字符串 [英] How can I change connection string of a stimulsoft report at run time
问题描述
之后从windows表单执行此报告并且运行良好。
< pre lang =c#> StiReport report = new StiReport();
string file = Environment.CurrentDirectory + \\Report\\PaySlipList.mrt跨度>;
report.Load(file);
report.ReportName = name;
report.Dictionary.Variables [ _ year]。Value = GlobalVar.AppDate_Year.ToString ();
report.Dictionary.Variables [ _ month]。Value = GlobalVar.AppDate_Month.ToString ();
report.Dictionary.Variables [ _ company]。Value = GlobalVar.Company.ToString ();
report.Show();
现在我的问题是如何在运行时更改数据源的连接字符串?
< blockquote>查看下面的文章。这将帮助您完成工作。
http://yizeng.me/2013/08/31/update-appsettings-and-custom-configuration-sections-in-appconfig-at-runtime / [ ^ ]
您可以将Config部分更新为运行时间。
请参阅以下代码以了解您的问题。
var config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
config.ConnectionStrings.ConnectionStrings [ GKon]。ConnectionString = newConnectionString; // 将您的领域与此结合在一起
config.Save(ConfigurationSaveMode.Modified,真跨度>);
ConfigurationManager.RefreshSection( connectionStrings);
StiReport report = new StiReport();
report.Load( MyReport.mrt);
report.Dictionary.Databases.Clear();
report.Dictionary.Databases.Add( new StiSqlDatabase( MyDatabase, 新连接字符串));
你应该加载到负载报告文件的位置。首先加载报告文件,然后清除数据集并设置连接字符串
hi every one. I created a report in stimulsoft. I created a datasource, and added an exiting stored procedure to it. then I assigned column this datasource to my report.
after that from a windows form I executed this report and that worked well.
StiReport report = new StiReport();
string file = Environment.CurrentDirectory + "\\Report\\PaySlipList.mrt";
report.Load(file);
report.ReportName = "name";
report.Dictionary.Variables["_year"].Value = GlobalVar.AppDate_Year.ToString();
report.Dictionary.Variables["_month"].Value = GlobalVar.AppDate_Month.ToString();
report.Dictionary.Variables["_company"].Value = GlobalVar.Company.ToString();
report.Show();
now my question is how can I change connection string of my datasource at runtime?
Check out below article. This will help you to get your job done.
http://yizeng.me/2013/08/31/update-appsettings-and-custom-configuration-sections-in-appconfig-at-runtime/[^]
You can update the Config sections as run time.
See the below code for specific to your problem.
var config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None); config.ConnectionStrings.ConnectionStrings["GKon"].ConnectionString = newConnectionString; //CONCATINATE YOUR FIELDS TOGETHER HERE config.Save(ConfigurationSaveMode.Modified, true); ConfigurationManager.RefreshSection("connectionStrings");
StiReport report = new StiReport(); report.Load("MyReport.mrt"); report.Dictionary.Databases.Clear(); report.Dictionary.Databases.Add(new StiSqlDatabase("MyDatabase", "new connection string"));
you should be cerefule to the position of load report file. at first load report file then clear data set and set connection string
这篇关于如何在运行时更改stimulsoft报告的连接字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!