2012-09-12 42 views
1

我在ASP.Net網頁上顯示Crystal報表時遇到問題。該網站只是一個內部網站,所以您會看到我已將文件路徑編碼到網站中。我覺得我非常接近這個工作,但我顯然錯過了一些東西。誰能幫忙?ASP.Net中的Crystal Report傳遞參數值並且沒有有效的報告源

他是我的代碼:

void BindReport() 
{ 
    ReportDocument rd = new ReportDocument(); 

    //Report is saved on an external server which I have full access too 
    rd.Load(@"\\MyServer\Reports\MyReport.rpt"); 
    rd.SetDatabaseLogon("UserName", "Password", "MyServer", "MyDatabase", true); 
    //The Report has 2 parameter and links directly to a stored procedure on a SQL Server 
    rd.SetParameterValue("@uspDateFrom", new DateTime(2012, 05, 01)); 
    rd.SetParameterValue("@uspDateTo", new DateTime(2012, 05, 31)); 
    CrystalReportViewer1.ReportSource = rd; 
    CrystalReportViewer1.ReuseParameterValuesOnRefresh = true; 
    CrystalReportViewer1.RefreshReport(); 
} 

//I call my report on a button click 
protected void buttonPreviewReport_Click(object sender, EventArgs e) 
{ 
    BindReport(); 
} 

當報告試圖運行我得到一個對話框彈出,詢問我的參數值,即使我已經通過了他們!?即使我在對話提示符中輸入它們,我也會收到一條消息,指出沒有有效的報告源可用。

有人有什麼想法嗎?

我使用ASP.Net 4.0

在此先感謝

回答

0

同樣的問題,我得到一次當我用水晶報表工作。

ParameterFields paramFields = new ParameterFields(); 

    ParameterField paramField = new ParameterField(); 

    ParameterDiscreteValue discreteVal = new ParameterDiscreteValue(); 

    paramField.ParameterFieldName = "@examid";// This is how you can send Parameter Value to the Crystal Report 


// Set the first discrete value and pass it to the parameter. 
    discreteVal.Value = ddlAllExam.SelectedValue;//Value from DropDown 

    paramField.CurrentValues.Add(discreteVal); 

    paramFields.Add(paramField); 

    CrystalReportViewer1.ParameterFieldInfo = paramFields; 

    string datasource = System.Configuration.ConfigurationManager.AppSettings["Data Source"].ToString(); 

    string Database = System.Configuration.ConfigurationManager.AppSettings["Database"].ToString(); 

    string Userid = System.Configuration.ConfigurationManager.AppSettings["Userid"].ToString(); 

    string Password = System.Configuration.ConfigurationManager.AppSettings["Password"].ToString(); 

    ReportDocument report = new ReportDocument(); 

    report.Load(Server.MapPath("~/Reports/AllExamReport.rpt"));//Here you can give the Path of external Server 

    report.SetDatabaseLogon(Userid, Password, datasource, Database); 

    CrystalReportViewer1.ReportSource = report; 

希望這會幫助你。

相關問題