使用c#显示水晶报告

时间:2013-04-25 15:06:52

标签: c# crystal-reports report

我对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);
}

3 个答案:

答案 0 :(得分:1)

    ReportDocument cryRpt = new ReportDocument();
    cryRpt.Load(@"CRYSTAL REPORT PATH HERE\CrystalReport1.rpt");
    crystalReportViewer1.ReportSource = cryRpt;
    crystalReportViewer1.Refresh();

答案 1 :(得分: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;
                    }

现在 尝试使用此代码作为参考代码....

答案 2 :(得分:0)

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

enter image description here

现在,您可以在按钮按下事件中调用此类报告

 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();
  }