0

Windows プロジェクト用にいくつかの Crystal Reports を作成しました。Visual Studio で実行すると、正常に機能します。(私はVS 2010を使用しています)。しかし、セットアップ プロジェクトを作成し、クライアント PC にソフトウェアをインストールすると、それらが機能しなくなります。次のエラーが表示されます。

http://tistus.srilanka-erickson.com/errors.html

次に表示されるのは、Crystal レポートをロードするために使用したボタン クリック イベント コードです。3 番目の try 句は、レポートをロードするためだけに使用されています。

private void buttonGenerateSecExportRpt_Click(object sender, EventArgs e)
    {
        CrystalDecisions.CrystalReports.Engine.ReportDocument cryRpt = new CrystalDecisions.CrystalReports.Engine.ReportDocument();
        if (comboBoxSecPlateType.Text != "" && comboBoxSecExPlateBrand.Text != "")
        {
            try
            {
                dtFrom.Format = DateTimePickerFormat.Custom;
                string periodfrom = dtFrom.Value.ToString("yyyy/MM/dd");
                dtTo.Format = DateTimePickerFormat.Custom;
                string periodto = dtTo.Value.ToString("yyyy/MM/dd");

                //cryRpt.VerifyDatabase();
                string fullPath = "..\\..\\SecondaryPlateExportReport.rpt";
                cryRpt.Load(fullPath);
                cryRpt.SetParameterValue("dateFromChecked", dtFrom.Checked);
                cryRpt.SetParameterValue("dateToChecked", dtTo.Checked);
                cryRpt.SetParameterValue("dtPeriodFrom", periodfrom);
                cryRpt.SetParameterValue("dtPeriodTo", periodto);
                cryRpt.SetParameterValue("PlateType", comboBoxSecPlateType.Text.Trim());
                cryRpt.SetParameterValue("PlateBrand", comboBoxSecExPlateBrand.Text.Trim());

            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            try
            {
                DbConnectionInfo.SetConnectionString(ConfigurationManager.ConnectionStrings["con"].ToString());
                TableLogOnInfo logOnInfo;
                ConnectionInfo connectionInfo;
                foreach (Table table in cryRpt.Database.Tables)
                {
                    logOnInfo = table.LogOnInfo;
                    connectionInfo = logOnInfo.ConnectionInfo;
                    // Set the Connection parameters.
                    connectionInfo.DatabaseName = DbConnectionInfo.InitialCatalog;
                    connectionInfo.ServerName = DbConnectionInfo.ServerName;
                    if (!DbConnectionInfo.UseIntegratedSecurity)
                    {
                        connectionInfo.Password = DbConnectionInfo.Password;
                        connectionInfo.UserID = DbConnectionInfo.UserName;
                    }
                    else
                    {
                        connectionInfo.IntegratedSecurity = true;
                    }
                    table.ApplyLogOnInfo(logOnInfo);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            try
            {
                crystalReportViewerSecEx.ReportSource = cryRpt;
                crystalReportViewerSecEx.Refresh();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
        else
        {
            MessageBox.Show("Please select both Plate Type and the Brand to Generate the Report!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
        }
    }

クライアント PC にソフトウェアを展開した後、Crystal レポートを機能させたいと考えています。どんな提案でも大歓迎です!

4

2 に答える 2

2
crystalReport.Load(@"C:\WINDOWS\Temp\samridhi.rpt");

セットアップを作成するときは、クリスタルレポートのパスを次のように置きます

C:\WINDOWS\Temp」に移動します

そしてur rptと.csファイルをコピーして、実行プロンプトではなくmycomputerで「 C:\WINDOWS\Temp 」に移動します


プロジェクトアプリケーションでクリスタルレポートのパスを確認するためだけにセットアップしない場合は、ここにあります

パスは

  crystalReport.Load(System.Windows.Forms.Application.StartupPath + "\\samridhi.rpt");
于 2012-11-24T09:55:18.767 に答える
0

シェハン、

.NET プロジェクトでは、ハードコードされたパスを使用しないことをお勧めします。Server.MapPath 変数を使用して文字列を動的に作成するのが最善です。

例として、using System.IO をプロジェクトに追加します。その後、Path.Combine メソッドを使用して文字列を作成できます。

    string mappath = HttpContext.Current.Server.MapPath("~/");
    Path.Combine(mappath, "Report Folder Path", "FileName.rpt");

「Report Folder Path」を静的文字列に配置して、変更を恐れずに複数回呼び出すこともできます。

于 2012-08-10T19:23:54.257 に答える