I have an error when passing my TextBox value to my Crystal Report:
System.Runtime.InteropServices.COMException(0x8002000B): Invalid index. (Exception from HRESULT: 0x8002000B(DIS_E_BADINDEX))
at CrystalDecisions.ReportAppServer.DataDefModel.FieldsClass.get_Item(Int32 Index)
at CrystalDecisions.CrystalReports.Engine.ParameterFieldDefinitions.get_Item(Int32 Index)
at CrystalDecisions.CrystalReports.Engine.ParameterFieldDefinitions.get_Item(String fieldName)
at WindowsFormsApplication1.Form15.button1_Click(Object sender, EventArgs e) in ..\Form15.cs: line 134
this is my code for getting my entered values in my textboxes to be shown in the report including the error line:
ParameterFieldDefinitions paramFieldDefinitions;
paramValue = new ParameterValues();
discreteValue = new ParameterDiscreteValue();
discreteValue.Value = Convert.ToString(txtYear.Text);
paramFieldDefinitions = CrystalReport81.DataDefinition.ParameterFields;
fieldDefinition = paramFieldDefinitions["Year"]; <-- the is the line 134
commonParam();
discreteValue.Value = Convert.ToString(comMonth.Text);
paramFieldDefinitions = CrystalReport81.DataDefinition.ParameterFields;
fieldDefinition = paramFieldDefinitions["Month"];
commonParam();
discreteValue.Value = Convert.ToString(Grade);
paramFieldDefinitions = CrystalReport81.DataDefinition.ParameterFields;
fieldDefinition = paramFieldDefinitions["Grade"];
commonParam();
discreteValue.Value = Convert.ToString(date);
paramFieldDefinitions = CrystalReport81.DataDefinition.ParameterFields;
fieldDefinition = paramFieldDefinitions["date"];
commonParam();
The codes below are for passing parameters to stored procedure: (This is running)
ParameterFields myParams = new ParameterFields();
ParameterField name = new ParameterField();
ParameterDiscreteValue valName = new ParameterDiscreteValue();
name.ParameterFieldName = "@Log_User";
valName.Value = comEmployee.Text;
name.CurrentValues.Add(valName);
myParams.Add(name);
ParameterField month = new ParameterField();
ParameterDiscreteValue valMonth = new ParameterDiscreteValue();
month.ParameterFieldName = "@Month";
valMonth.Value = Convert.ToInt32(iMonth);
month.CurrentValues.Add(valMonth);
myParams.Add(month);
ParameterField year = new ParameterField();
ParameterDiscreteValue valYear = new ParameterDiscreteValue();
year.ParameterFieldName = "@Year";
valYear.Value = Convert.ToInt32(txtYear.Text);
year.CurrentValues.Add(valYear);
myParams.Add(year);
crystalReportViewer1.ParameterFieldInfo = myParams;
crystalReportViewer1.ReportSource = CrystalReport81;
crystalReportViewer1.Refresh();
I really do not know how to add the values from my textboxes to my Crystal Report.. Please help me to do it...
Thank you and God bless :D
TextObject yr = (TextObject)CrystalReport81.ReportDefinition.Sections["Section3"].ReportObjects["Text1"];
yr.Text = txtYear.Text;
FORM Textbox --> CRYSTAL REPORT Textbox
By adding the code above will enable you to show the value you entered in the textboxes.. but first you should have an empty Textbox in your Crystal Report because that will catch the value you throw from your FORM Textbox
I hope it can help others.. as it helped me a lot..
if (textBox1.Text != "")
{
//just Intlization Object's Here n Access Data using .xsd in Project
DataSet1.DataTable2DataTable dtcity = null;
DataSet1TableAdapters.DataTable2TableAdapter adpt = null;
ParameterFields myParams = null;
ParameterField name = null;
CrystalReport1 rpt = null;
ParameterDiscreteValue valYear = null;
try
{
// For Get Data For DB
dtcity = new DataSet1.DataTable2DataTable();
adpt = new DataSet1TableAdapters.DataTable2TableAdapter();
dtcity = adpt.GetStateNCityData();
rpt = new CrystalReport1();
rpt.Database.Tables["DataTable2"].SetDataSource(dtcity.Copy() as DataTable);
//For Get Data For DB
//Add Paramater
myParams = new ParameterFields();
name = new ParameterField();
valYear = new ParameterDiscreteValue();
name.ParameterFieldName = "@textName";
valYear.Value = textBox1.Text;
name.CurrentValues.Add(valYear);
myParams.Add(name);
crystalReportViewer1.ParameterFieldInfo = myParams;
//Add Paramater
crystalReportViewer1.ReportSource = rpt;
}
catch (Exception ex)
{
}
finally { }
}
else
{
MessageBox.Show("Please Enter Name");
textBox1.Focus();
}
In That @textName
is a Parameter which you have to add in Crystal Report as a ParameterFields..n drag n drop it in you Report section easily.
User contributions licensed under CC BY-SA 3.0