水晶报表:索引无效.(来自 HRESULT 的异常:0x8002000B (DISP_E_BADINDEX)) [英] Crystal Report: Invalid index. (Exception from HRESULT: 0x8002000B (DISP_E_BADINDEX))

查看:14
本文介绍了水晶报表:索引无效.(来自 HRESULT 的异常:0x8002000B (DISP_E_BADINDEX))的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法将值传递给报告.

这是我的代码:

public void GLRPT(){尝试{ReportClass rptH = new ReportClass();rptH.FileName = Server.MapPath("~/Rpts/G1.rpt");rptH.Load();字符串 df = Session["fromdate"].ToString();string dt = Session["todate"].ToString();日期时间 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");}捕捉(例外前){Response.Write(ex.Message);}}

我不知道为什么会看到此错误:
索引无效.(HRESULT 异常:0x8002000B (DISP_E_BADINDEX))

解决方案

我们应该像这样传递参数值:

rptH.SetParameterValue("Date_From", fromdate);//正确的

不是

rptH.SetParameterValue("?Date_From", fromdate);//不正确

然后我们必须为报表提供数据库访问权限,因为如果不登录数据库,报表将无法打开.这是代码:

ReportDocument rptH = new ReportDocument();TableLogOnInfos crtableLogoninfos = new TableLogOnInfos();TableLogOnInfo crtableLogoninfo = new TableLogOnInfo();ConnectionInfo crConnectionInfo = new ConnectionInfo();表 CrTables;rptH.Load(Server.MapPath("~/Rpts/G1.rpt"));字符串 df = Session["fromdate"].ToString();string dt = Session["todate"].ToString();日期时间 fromdate = DateTime.Parse(df);DateTime todate = DateTime.Parse(dt);rptH.SetParameterValue("Date_From", fromdate);rptH.SetParameterValue("Date_To", todate);crConnectionInfo.ServerName = "您的服务器名称";crConnectionInfo.DatabaseName = "你的数据库名称";crConnectionInfo.UserID = "你的数据库用户名";crConnectionInfo.Password = "你的数据库密码";CrTables = rptH.Database.Tables;foreach(CrTables 中的CrystalDecisions.CrystalReports.Engine.Table CrTable){crtableLogoninfo = CrTable.LogOnInfo;crtableLogoninfo.ConnectionInfo = crConnectionInfo;CrTable.ApplyLogOnInfo(crtableLogoninfo);}rptH.ExportToHttpResponse(ExportFormatType.PortableDocFormat, System.Web.HttpContext.Current.Response, false, "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屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆