首页 文章

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

提问于
浏览
0

有人可以帮我解决我的问题 . 我已经有了这个代码,但我似乎无法将两者结合起来 . 图例:dt1 =数据集; crpt = Crystal Report File

这是我的代码,用于将数据库值加载到使用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” . 我尝试组合这些代码,但它会提示“参数值不正确”的消息 . 任何人?

1 回答

相关问题