繁体   English   中英

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

[英]Passing Textbox value to Crystal Report textbox

大家好,我在将文本框值传递到Crystal报表中的文本框对象时遇到问题。

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

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

它提示一条错误消息,提示:索引超出了数组的范围。

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

这提示:无效的索引

这是我用于加载记录的代码。 除传递文本框的值外,其他所有操作均有效。

传说:

dt1 =数据集

crpt.rpt =水晶报表文件

            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();

任何人?

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

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

...设置 CrystalReportViewer.ReportSource ,但如果你得到的错误,也许你有在参数名称拼写错误或参数未在首位的报告文件(.RPT)创建的。

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

CrystalReport2 objRpt = new CrystalReport2();

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

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

以下应该为您工作:

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

暂无
暂无

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

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