2014-04-19 67 views
1

水晶報表顯示參數當加載報表時提示。加載水晶報表時顯示參數提示

我加載報告準則是: -

TableLogOnInfo logOnInfo = new TableLogOnInfo(); 

       logOnInfo.ConnectionInfo.ServerName = System.Configuration.ConfigurationManager.AppSettings["ServerName"]; 
       logOnInfo.ConnectionInfo.DatabaseName = System.Configuration.ConfigurationManager.AppSettings["DBName"]; 
       logOnInfo.ConnectionInfo.IntegratedSecurity = false; 
       logOnInfo.ConnectionInfo.UserID = System.Configuration.ConfigurationManager.AppSettings["UID"]; 
       logOnInfo.ConnectionInfo.Password = System.Configuration.ConfigurationManager.AppSettings["PWD"]; 

       foreach (CrystalDecisions.CrystalReports.Engine.Table tbl in SchoolExpenseReport.ReportDocument.Database.Tables) 
        tbl.ApplyLogOnInfo(logOnInfo); 

       ParameterValues pvSchoolExpense = new ParameterValues(); 
       ParameterDiscreteValue pdvFomDate = new ParameterDiscreteValue(); 
       ParameterDiscreteValue pdvToDate = new ParameterDiscreteValue(); 

       pdvFomDate.Value = txtFromDate.Text; 
       pdvToDate.Value = txtToDate.Text; 

       SchoolExpenseReport.ReportDocument.DataDefinition.ParameterFields["FromDate"].CurrentValues.Clear(); 
       pvSchoolExpense.Add(pdvFomDate); 
       SchoolExpenseReport.ReportDocument.DataDefinition.ParameterFields["FromDate"].ApplyCurrentValues(pvSchoolExpense); 

       SchoolExpenseReport.ReportDocument.DataDefinition.ParameterFields["ToDate"].CurrentValues.Clear(); 
       pvSchoolExpense.Add(pdvToDate); 
       SchoolExpenseReport.ReportDocument.DataDefinition.ParameterFields["ToDate"].ApplyCurrentValues(pvSchoolExpense); 

       SchoolExpenseReportViewer.ReportSource = SchoolExpenseReport; 
       SchoolExpenseReportViewer.DataBind(); 
       SchoolExpenseReportViewer.RefreshReport(); 
       SchoolExpenseReport.Visible = true; 

顯示參數提示如下 enter image description here

+0

哪裏是一個問題嗎? –

+0

我認爲問題在於OP提供了參數值,但報告仍然在提示他們(它不應該這樣做)。 –

回答

0

我不是太熟悉添加這樣的參數。我通常使用.SetParameterValue()

當我將日期設置爲參數值時,它們通常採用DateTime格式,但我看到您只是分配字符串值。

嘗試修改此:

pdvFomDate.Value = txtFromDate.Text; 
pdvToDate.Value = txtToDate.Text; 

爲了這個(改變,不管以何種格式字符串中的日期看起來像在TextBox):

pdvFomDate.Value = DateTime.ParseExact(txtFromDate.Text, "MM/dd/yyyy"); 
pdvToDate.Value = DateTime.ParseExact(txtToDate.Text, "MM/dd/yyyy"); 

FWIW,我會考慮使用日期選擇器控件而不是文本框來接受來自用戶的日期值。


如果還是不行,請嘗試設置參數值的這種替代語法:

var fromDate = DateTime.ParseExact(txtFromDate.Text, "MM/dd/yyyy"); 

SchoolExpenseReport.ReportDocument.SetParameterValue("FromDate", fromDate); 
+0

我有另一個頁面,只有下拉列表,但頁面上發生的相同。 – user3355115