文本框的值传递给水晶报表

通过我的文本框的值到我的水晶报表时,我有一个错误:

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

这是我得到在我的文本框中输入我的价值观中的报告,包括错误行中显示的代码:

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

下面的代码将参数传递到存储过程:(这是运行)

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

我真的不知道如何从我的文本框到我的水晶报表添加值。请帮我做...

谢谢你,上帝保佑:D

--------------解决方案-------------

TextObject yr = (TextObject)CrystalReport81.ReportDefinition.Sections["Section3"].ReportObjects["Text1"];
yr.Text = txtYear.Text;

FORM文本框 - >水晶报表文本框

通过添加上面的代码将使您能够显示您在文本框中输入的值..但首先你应该有一个空的文本框在Crystal报表,因为这会从表单文本框抓住你扔值

我希望它可以帮助别人..因为它帮了我很多..

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

@textName是你必须在Crystal报表添加为ParameterFields..n拖ñ下降它可以轻松地报告部分的参数。

分类:C# 时间:2015-03-15 人气:0
分享到:

相关文章

Copyright (C) 55228885.com, All Rights Reserved.

55228885 版权所有 京ICP备15002868号

processed in 1.252 (s). 10 q(s)