![](/img/trans.png)
[英]Setting/Passing a Value to a Parameter to a Crystal Report in c# is Not Working
[英]Passing Textbox value to Crystal Report Parameter c#
有人可以幫忙解決我的問題。 我已經有了用於此的代碼,但是我似乎無法將兩者結合起來。 圖例:dt1 =數據集; crpt =水晶報表文件
這是我的代碼,用於將數據庫值加載到使用txtGender文本框的值過濾的Crystal Report中:
SqlConnection conn = conString.getCon();
ReportDocument cy = new ReportDocument();
dt1 ds = new dt1();
conn.Open();
cy.Load(Application.StartupPath + @"\crpt.rpt");
SqlDataAdapter da = new SqlDataAdapter("exec viewInfo @gen", conn);
da.SelectCommand.Parameters.AddWithValue("@gen", txtGender.Text);
da.Fill(ds.Info);
cy.SetDataSource(ds);
crystalReportViewer1.ReportSource = cy;
conn.Close();
這是我的用於將文本框txtGender值傳遞到名為“ Gen”的Crystal Report Parameter對象中的代碼:
ParameterFields pField = new ParameterFields();
ParameterField pTitle = new ParameterField();
ParameterDiscreteValue pValue = new ParameterDiscreteValue();
pTitle.ParameterFieldName = "Gen"; //the name of the field @ Crystal Report
pValue.Value = txtGender.Text; //sending the text box value
pTitle.CurrentValues.Add(pValue);
pField.Add(pTitle);
crystalReportViewer1.ParameterFieldInfo = pField;
crpt objBT = new crpt();
objBT.Refresh();
crystalReportViewer1.ReportSource = objBT;
我的問題是如何結合這兩個代碼,以便在文本框中輸入值時,它將數據庫值加載到Crystal Report中,並將文本框的值傳遞到Crystal Report參數對象“ Gen”中。 我嘗試合並這些代碼,但提示消息“參數值不正確”。 任何人?
希望以下參考鏈接可以為您解決問題。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.