首页 文章

将文本框值传递给Crystal Report文本框

提问于
浏览
0

大家好我在将文本框值传递到水晶报表中的文本框对象时遇到问题 .

到目前为止,这些是我尝试过的以下代码:

TextObject yr = (TextObject)cy.ReportDefinition.Sections["Section1"].ReportObjects["gender1"];
     yr.Text = txtGender.Text;

它会提示错误消息:索引超出了数组的范围 .

cy.SetParameterValue("gender1", txtGender.text);

这个提示:索引无效

这是我加载记录的代码 . 除了传递文本框的值之外,一切都有效 .

传说:

dt1 =数据集

crpt.rpt = Crystal报告文件

SqlConnection conn = conString.getCon();
            ReportDocument cy = new ReportDocument();

            conn.Open();
            cy.Load(Application.StartupPath + @"\crpt.rpt");

            TextObject gr = (TextObject)cy.ReportDefinition.Sections["Section1"].ReportObjects["gender1"];
            gr.Text = txtGender.Text;

            SqlDataAdapter da = new SqlDataAdapter("exec viewInfo @gen", conn);
            da.SelectCommand.Parameters.AddWithValue("@gen", txtGender.Text);

            dt1 ds = new dt1();
            da.Fill(ds.Info);
            cy.SetDataSource(ds);

            crystalReportViewer1.ReportSource = cy;
            conn.Close();

任何人?

3 回答

  • 0

    如果您尝试在报告中设置参数,则可以使用

    crystalReportViewer1.ParameterFieldInfo["gender1"].CurrentValues.Add(txtGender.Text)
    

    ...设置 CrystalReportViewer.ReportSource 之后,如果你首先在报告文件(.rpt)中创建了're getting that error, maybe you have a typo in the parameter name or the parameter wasn' .

    如果您尝试使用 txtGender.Text 过滤数据,也可以查看 ReportDocument.RecordSelectionFormula .

  • 0
    CrystalReport2 objRpt = new CrystalReport2();
    
    TextObject accntCode = (TextObject)objRpt.ReportDefinition.Sections["Section2"].ReportObjects["codeText11"];
    accntCode.Text = codevalue;
    

    只需使用此功能,您无需使用报告文档 . 您可以直接将值分配给Crystal Report中的字段对象 .

  • -1

    以下内容对您有用:

    TextObject text =(TextObject)CrystalReport21.ReportDefinition.Sections["Section3"].ReportObjects["Text19"];
                text.Text = comboBox2.Text;
                crystalReportViewer1.ReportSource = name your crystalreport;
                crystalReportViewer1.Refresh();
    

相关问题