[英]displaying a crystal report using c#
我对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);
}
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;
}
现在尝试将此代码作为参考代码。...
最好添加Windows窗体并将Crystel报告格式拖放到窗体中。它会自动设置为全屏显示。您可以使用该报告格式查看应用程序中的所有crystel报告。 注意:您需要根据我们的Visual Studio版本安装Crystel报告运行时兼容版本。
现在,您可以在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!");
}
}
然后在报表加载事件中编写此代码
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.