如何在运行时更改stimulsoft报告的连接字符串 [英] How can I change connection string of a stimulsoft report at run time

查看:143
本文介绍了如何在运行时更改stimulsoft报告的连接字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

每个人都好。我在stimulsoft创建了一份报告。我创建了一个数据源,并为其添加了一个退出的存储过程。然后我将这个数据源列分配到我的报告。

之后从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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆