繁体   English   中英

将文本框值传递给Crystal Report参数c#

[英]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”中。 我尝试合并这些代码,但提示消息“参数值不正确”。 任何人?

希望以下参考链接可以为您解决问题。

C#Crystal Reports字符串参数

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM