2012-12-07 133 views
0

我在水晶報表中創建了一個@Month作爲參數名稱,並插入到報表標題部分。水晶報表參數

當我運行報告總是通過顯示一個框詢問參數。我如何通過代碼。我現有的代碼是

MyReport rpt = new MyReport(); 
var srcData = ; //here i added my LINQ statement to select the data 
rpt.SetDataSource(srcData); 
ParameterDiscreteValue pdValue = new ParameterDiscreteValue(); 
pdValue.Value = combo2.SelectedValue; 
rpt.ParameterFields["@Month"].CurrentValues.Add(pdValue); 
this.ReportViewer1.ReportSource = rpt; 
this.ReportViewer1.RefreshReport(); 

我在哪裏做錯了?

回答

0

如果它不起作用,它表明一個錯字或什麼。嘗試分析rpt.ParameterFields(設置斷點並觀察)。你有參數名稱是否正確?數據類型?

+0

遐我得到它的正確我傳遞給組合框選定值。如果您未刷新,已將組合框選定的值返回爲對象 – Akhil

0

我在添加參數時也遇到了麻煩。下面是我的工作是什麼一個例子:

我找到

string ponumber = Request.QueryString["ponumber"].ToString(); 
string receiptno = Request.QueryString["receiptno"].ToString(); 

    // Put Away Report 

    CrystalReportSource CrystalReportSource1 = new CrystalReportSource(); 
    CrystalReportViewer CrystalReportViewer1 = new CrystalReportViewer(); 

    CrystalReportViewer1.ReportSource = CrystalReportSource1; 
    CrystalReportViewer1.EnableParameterPrompt = false; 
    CrystalReportSource1.Report.FileName = "Report3.rpt"; 
    CrystalReportSource1.EnableCaching = false; 

    // This will set the values of my two parameters in the report 
    CrystalReportSource1.ReportDocument.SetParameterValue(0, ponumber); 
    CrystalReportSource1.ReportDocument.SetParameterValue(1, receiptno); 



    TableLogOnInfo logOnInfo = new TableLogOnInfo(); 

    logOnInfo.ConnectionInfo.ServerName = ConfigurationManager.AppSettings["WarehouseReportServerName"]; 
    logOnInfo.ConnectionInfo.DatabaseName = ConfigurationManager.AppSettings["WarehouseReportDatabaseName"]; 
    logOnInfo.ConnectionInfo.UserID = ConfigurationManager.AppSettings["WarehouseReportUserID"]; 
    logOnInfo.ConnectionInfo.Password = ConfigurationManager.AppSettings["WarehouseReportPassword"]; 

    TableLogOnInfos infos = new TableLogOnInfos(); 
    infos.Add(logOnInfo); 
    CrystalReportViewer1.LogOnInfo = infos; 

    maindiv.Controls.Add(CrystalReportSource1); 
    maindiv.Controls.Add(CrystalReportViewer1); 


    CrystalReportViewer1.DataBind();