水晶报表:无效的索引。 (从HRESULT异常:0x8002000B(DISP_E_BADINDEX)) [英] Crystal Report: Invalid index. (Exception from HRESULT: 0x8002000B (DISP_E_BADINDEX))
问题描述
我不能值传递到报告。
这是我的code:
公共无效GLRPT()
{
尝试
{ ReportClass rptH =新ReportClass();
rptH.FileName =使用Server.Mappath(〜/ RPTS / G1.rpt);
rptH.Load(); 字符串DF =会话[寄件者]的ToString()。
串DT =会话[TODATE]的ToString()。
日期时间寄件者= DateTime.Parse(DF);
日期时间TODATE = DateTime.Parse(DT); rptH.SetParameterValue(Date_From?,寄件者);
rptH.SetParameterValue(?DATE_TOTODATE);
rptH.ExportToHtt presponse(ExportFormatType.PortableDocFormat,System.Web.HttpContext.Current.Response,假的,GL);
}
赶上(异常前)
{
的Response.Write(ex.Message);
}
}
我不知道为什么我会看到此错误:
结果
无效的索引。 (从HRESULT异常:0x8002000B(DISP_E_BADINDEX))
我们应该传递的参数值是这样的:
rptH.SetParameterValue(Date_From,寄件者); //正确
不会
rptH.SetParameterValue(?Date_From,寄件者); //不正确
然后,我们就要给数据库访问以报告,因为没有登录到数据库将无法打开该报告。
这里是code:
的ReportDocument rptH =新的ReportDocument();
TableLogOnInfos crtableLogoninfos =新TableLogOnInfos();
TableLogOnInfo crtableLogoninfo =新TableLogOnInfo();
ConnectionInfo crConnectionInfo =新ConnectionInfo();
表CrTables;rptH.Load(使用Server.Mappath(〜/ RPTS / G1.rpt));字符串DF =会话[寄件者]的ToString()。
串DT =会话[TODATE]的ToString()。
日期时间寄件者= DateTime.Parse(DF);
日期时间TODATE = DateTime.Parse(DT);rptH.SetParameterValue(Date_From,寄件者);
rptH.SetParameterValue(DATE_TO,TODATE);crConnectionInfo.ServerName =服务器名称;
crConnectionInfo.DatabaseName =数据库名称;
crConnectionInfo.UserID =您的数据库用户名;
crConnectionInfo.Password =你的数据库密码;CrTables = rptH.Database.Tables;
的foreach(CrystalDecisions.CrystalReports.Engine.Table CrTable在CrTables)
{
crtableLogoninfo = CrTable.LogOnInfo;
crtableLogoninfo.ConnectionInfo = crConnectionInfo;
CrTable.ApplyLogOnInfo(crtableLogoninfo);
}rptH.ExportToHtt presponse(ExportFormatType.PortableDocFormat,System.Web.HttpContext.Current.Response,假的,GL);
我们必须调用参数的名称没有任何额外的字符如
@ 或?,仅仅只有参数的名称本身。
块引用>I can not pass values to the report.
This is my code:
public void GLRPT() { try { ReportClass rptH = new ReportClass(); rptH.FileName = Server.MapPath("~/Rpts/G1.rpt"); rptH.Load(); string df = Session["fromdate"].ToString(); string dt = Session["todate"].ToString(); DateTime fromdate = DateTime.Parse(df); DateTime todate = DateTime.Parse(dt); rptH.SetParameterValue("?Date_From", fromdate); rptH.SetParameterValue("?Date_To", todate); rptH.ExportToHttpResponse(ExportFormatType.PortableDocFormat, System.Web.HttpContext.Current.Response, false, "GL"); } catch (Exception ex) { Response.Write(ex.Message); } }
I don't know why I see this error:
Invalid index. (Exception from HRESULT: 0x8002000B (DISP_E_BADINDEX))解决方案We should pass the parameter value like this:
rptH.SetParameterValue("Date_From", fromdate); //correct
NOT
rptH.SetParameterValue("?Date_From", fromdate); //incorrect
Then we we must give database access to the report because without login to database the report will not be opened. and here is the code:
ReportDocument rptH = new ReportDocument(); TableLogOnInfos crtableLogoninfos = new TableLogOnInfos(); TableLogOnInfo crtableLogoninfo = new TableLogOnInfo(); ConnectionInfo crConnectionInfo = new ConnectionInfo(); Tables CrTables; rptH.Load(Server.MapPath("~/Rpts/G1.rpt")); string df = Session["fromdate"].ToString(); string dt = Session["todate"].ToString(); DateTime fromdate = DateTime.Parse(df); DateTime todate = DateTime.Parse(dt); rptH.SetParameterValue("Date_From", fromdate); rptH.SetParameterValue("Date_To", todate); crConnectionInfo.ServerName = "YOUR SERVER NAME"; crConnectionInfo.DatabaseName = "YOUR DATABASE NAME"; crConnectionInfo.UserID = "YOUR DATABASE USERNAME"; crConnectionInfo.Password = "YOUR DATABASE PASSWORD"; CrTables = rptH.Database.Tables; foreach (CrystalDecisions.CrystalReports.Engine.Table CrTable in CrTables) { crtableLogoninfo = CrTable.LogOnInfo; crtableLogoninfo.ConnectionInfo = crConnectionInfo; CrTable.ApplyLogOnInfo(crtableLogoninfo); } rptH.ExportToHttpResponse(ExportFormatType.PortableDocFormat, System.Web.HttpContext.Current.Response, false, "GL");
We must call the parameter's name without any additional character such as @ or ?, just only the parameter's name itself.
这篇关于水晶报表:无效的索引。 (从HRESULT异常:0x8002000B(DISP_E_BADINDEX))的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!