displaying a crystal report using c#

☆樱花仙子☆ 提交于 2019-12-24 05:39:24

问题


I am relatively new to C# and i have never used Crystal Reports so i apologise if i do use the incorrect terminology. I am trying to display a report which is called by some C# code. 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);
}

回答1:


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



回答2:


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....




回答3:


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.Note:You need to install Crystel report run time compatible version according our Visual studio version.

Now you can call to report like this in Button press event

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


来源:https://stackoverflow.com/questions/16218371/displaying-a-crystal-report-using-c-sharp

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!