2

我对 C# 比较陌生,而且我从未使用过 Crystal Reports,所以如果我确实使用了不正确的术语,我深表歉意。我正在尝试显示由某些 C# 代码调用的报告。通过在这里跟踪很多线程,我设法提出了以下代码,它确实构建了一个调试。但是,当代码运行时,它不会显示报告。

这是代码:

private void forAllQualitiesToolStripMenuItem_Click(object sender, EventArgs e) {
    CrystalReportViewer rv = new CrystalReportViewer();
    string reportPath = @"C:\Documents and Settings\rp\Desktop\StockByStatus.rpt"; 

    ReportDocument r = new ReportDocument();

    r.Load(reportPath);
    rv.Visible = false; // i put this in because when i ran the code without it, it said the report must not be visible and the program would fall down
    rv.ReportSource = r;
    rv.InitReportViewer();
    ShowDialog(rv);
}
4

3 回答 3

1
    ReportDocument cryRpt = new ReportDocument();
    cryRpt.Load(@"CRYSTAL REPORT PATH HERE\CrystalReport1.rpt");
    crystalReportViewer1.ReportSource = cryRpt;
    crystalReportViewer1.Refresh();
于 2013-09-10T06:14:51.533 回答
0
private void forAllQualitiesToolStripMenuItem_Click(object sender, EventArgs e) {

                    {
                        CrystalReportViewer rv = new CrystalReportViewer();
                        doc = new ReportDocument();
                        doc.Load(Server.MapPath("MR.rpt"));
                        doc.SetDatabaseLogon("sa", "Admin123", "vivek", "PURCHASE", false);
                        reportdocument.SetParameterValue("@MRNO", ddlmrno.SelectedValue);
                        rv .ReportSource = doc;
                    }

现在试试这个代码作为参考代码....

于 2013-04-26T05:03:31.727 回答
0

最好添加 Windows 表单并将 Crystel 报表查看器拖放到表单中。它会自动设置为全屏。您可以使用报表查看器查看应用程序中的所有晶体报表。注意:您需要根据我们的 Visual Studio 版本安装 Crystel 报告运行时兼容版本。

在此处输入图像描述

现在您可以在按钮按下事件中调用这样的报告

 private void btOPdetailRep_Click(object sender, EventArgs e)
 {
   try
  {
    load();
    frmReports.printproparty = 7;   //7 what i assign numer for identify report
    frmReports objshow = new frmReports();
    objshow.ShowDialog();
  }
    catch (Exception ex)
  {
    MessageBox.Show("Details Printing Error!");
  }
}

然后在报告表单加载事件中编写此代码

string username = "sa";       //USERNAME AND PASSWORD FOR REPORT LOADING
 string password = "123";
if (printproparty == 7)
  {
   ReportDocument cryRpt = new ReportDocument();
   cryRpt.Load(@"op payment.rpt");
   cryRpt.SetDatabaseLogon(username, password);
   reports.ReportSource = cryRpt;
   reports.RefreshReport();
   reports.Refresh();
  }
于 2017-04-05T09:28:23.083 回答