简体   繁体   中英

Dynamic load .rpt in C#

try
{
     string spath = AppDomain.CurrentDomain.BaseDirectory;
     spath += "myReportFileName.rpt";

     ReportDocument cryRpt = new ReportDocument();
     cryRpt.Load(spath);

     cryRpt.DataSourceConnections[0].SetConnection("Server Name", "DB Name", true);
     cryRpt.DataSourceConnections[0].IntegratedSecurity = true;
     cryRpt.SetParameterValue("Field Name", "Value");
     cryRpt.RecordSelectionFormula = "Correct Formula";

     crystalReportViewer1.ReportSource = cryRpt;
     crystalReportViewer1.Refresh();
}
catch (System.Exception ex)
{
     MessageBox.Show("Error: " + ex.Message);
}

In my system, this code is ok. But in other system, It has error. I installed in all other systems crystal report correctly.

This code was executing with error:

crystaldecisions.crystalreports.engine.reportdocument' threw an exception

Then I executed CRRuntime_32bit_13_0_3.msi in client system. That error solved But other problem:

After to run code, the "Database Login" dialog is showing, and I don't connect to database automatically, and don't view the report file!!!

Please help me, what do I have to do?

I solved my problem. :) when I was creating the project , the crystalReport version 10 had was installed on my system. therefor I choosed "crystalReportViewer version 10" from Toolbox Item. I uninstalled version 10 of crystal report and installed version 11. In next step, I deleted crystalReportViewer from toolbox of visual studio then again choosed "crystalReportViewer version 11" from Toolbox Item.

now my project and created exe file, executes correctly in all systam that has crystall report vesion 10 later.

thank you! @rene :)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM