2013-04-25 106 views
1

我對C#相對較新,我從來沒有使用過水晶報表,所以我道歉如果我使用不正確的術語。我試圖顯示一個由某些C#代碼調用的報告。通過遵循這裏的很多線程,我設法得到了構建調試的以下代碼。但是,代碼運行時,它不會顯示報告。顯示使用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); 
} 
+1

我處理了SAP的大約6個星期試圖讓一些水晶報告在.NET 4.5下穩定工作。當我繼續遇到問題並建議我們的公司可能更適合使用SSRS時,SAP的技術支持人員認爲這對我們來說可能是更好的解決方案。 Crystal是SAP的紅頭髮的繼子女。支持是可怕的。除非您的公司已經將大筆資金投入到SAP的口袋中,否則您可能會獲得更好的支持解決方案。 – Pete 2013-04-25 17:58:15

回答

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

現在 試試這個代碼作爲參考代碼....

+0

感謝您的回覆。我應該補充說,這是爲c#.net。所以我不認爲這會工作,因爲我的解決方案中沒有任何aspx文件。 – user2115138 2013-04-26 07:47:52

0

其更好您添加Windows窗體和拖放Crystel報告viwer自動設置爲full screen.thart報告viwer,您可以在您的應用程序中查看所有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(); 
    }