[英]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.