简体   繁体   English

使用C#显示水晶报表

[英]displaying a crystal report using c#

I am relatively new to C# and i have never used Crystal Reports so i apologise if i do use the incorrect terminology. 我对C#相对较新,并且我从未使用过Crystal Reports,因此如果我使用的术语不正确,我深表歉意。 I am trying to display a report which is called by some C# code. 我正在尝试显示由某些C#代码调用的报告。 By following a lot of threads on here, i have managed to come up with the following code which does build an debug. 通过在此处跟踪大量线程,我设法提出了以下代码,这些代码的确建立了调试功能。 However, when the code is run, it does not display the report. 但是,运行代码时,它不会显示报告。

Here is the code: 这是代码:

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);
}
    ReportDocument cryRpt = new ReportDocument();
    cryRpt.Load(@"CRYSTAL REPORT PATH HERE\CrystalReport1.rpt");
    crystalReportViewer1.ReportSource = cryRpt;
    crystalReportViewer1.Refresh();
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;
                    }

Now Try this code as reference code.... 现在尝试将此代码作为参考代码。...

Its Better you add windows form and drag and drop Crystel report viwer to form.It's automatically set as full screen.thart report viwer you can used view all crystel reports in your Application. 最好添加Windows窗体并将Crystel报告格式拖放到窗体中。它会自动设置为全屏显示。您可以使用该报告格式查看应用程序中的所有crystel报告。 Note:You need to install Crystel report run time compatible version according our Visual studio version. 注意:您需要根据我们的Visual Studio版本安装Crystel报告运行时兼容版本。

在此处输入图片说明

Now you can call to report like this in Button press event 现在,您可以在Button按下事件中致电报告

 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!");
  }
}

then in report form loading event write this code 然后在报表加载事件中编写此代码

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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