简体   繁体   English

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

[英]Passing Textbox value to Crystal Report Parameter c#

Could someone please help with my problem. 有人可以帮忙解决我的问题。 I already have the codes for this but I can't seem to combine the two. 我已经有了用于此的代码,但是我似乎无法将两者结合起来。 Legend: dt1 = Dataset; 图例:dt1 =数据集; crpt = Crystal Report File crpt =水晶报表文件

This is my code for loading the database values into the Crystal Report filtered with the value of the txtGender textbox: 这是我的代码,用于将数据库值加载到使用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();

While this is my code for Passing the textbox txtGender value into the Crystal Report Parameter object named "Gen": 这是我的用于将文本框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;

My problem is how do I combine these two codes so that when I enter the value in the textbox it will load the database values into the Crystal Report and pass the value of the textbox into the Crystal Report Parameter Object "Gen". 我的问题是如何结合这两个代码,以便在文本框中输入值时,它将数据库值加载到Crystal Report中,并将文本框的值传递到Crystal Report参数对象“ Gen”中。 I have tried combining these codes but it prompts a message "Parameter value is incorrect". 我尝试合并这些代码,但提示消息“参数值不正确”。 Anyone? 任何人?

I hope the following reference link will help for your problem. 希望以下参考链接可以为您解决问题。

C# Crystal Reports String parameter C#Crystal Reports字符串参数

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

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