Reputation: 92
Hello everyone I have a problem passing my textbox value into the textbox object in the crystal report.
so far these are the following codes that I have tried:
TextObject yr = (TextObject)cy.ReportDefinition.Sections["Section1"].ReportObjects["gender1"];
yr.Text = txtGender.Text;
It prompts with an error message saying: Index was outside the bounds of the array.
cy.SetParameterValue("gender1", txtGender.text);
This one prompts: Invalid Index
This is my code for loading the records. Everything works except passing the value of the textbox.
Legend:
dt1 = Dataset
crpt.rpt = Crystal Report File
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();
Anyone?
Upvotes: 0
Views: 2625
Reputation: 1
The following should work for you:
TextObject text =(TextObject)CrystalReport21.ReportDefinition.Sections["Section3"].ReportObjects["Text19"];
text.Text = comboBox2.Text;
crystalReportViewer1.ReportSource = name your crystalreport;
crystalReportViewer1.Refresh();
Upvotes: -1
Reputation: 1
CrystalReport2 objRpt = new CrystalReport2();
TextObject accntCode = (TextObject)objRpt.ReportDefinition.Sections["Section2"].ReportObjects["codeText11"];
accntCode.Text = codevalue;
Just use this, you don't need to use report document. You can directly assign values to the field object in your Crystal Report.
Upvotes: 0
Reputation: 4997
If you're trying to set a parameter in the report, you can use
crystalReportViewer1.ParameterFieldInfo["gender1"].CurrentValues.Add(txtGender.Text)
...after setting the CrystalReportViewer.ReportSource
, though if you're getting that error, maybe you have a typo in the parameter name or the parameter wasn't created in the report file (.rpt) in the first place.
You could also look into ReportDocument.RecordSelectionFormula
if you're trying to use txtGender.Text
to filter data.
Upvotes: 0