gpt4 book ai didi

asp.net-mvc - Crystal 报表 : Invalid index.(HRESULT 异常:0x8002000B (DISP_E_BADINDEX))

转载 作者:搜寻专家 更新时间:2023-10-30 23:40:12 25 4
gpt4 key购买 nike

我无法将值传递给报表。

这是我的代码:

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

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

最佳答案

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

rptH.SetParameterValue("Date_From", fromdate); //correct

rptH.SetParameterValue("?Date_From", fromdate); //incorrect

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

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.

关于asp.net-mvc - Crystal 报表 : Invalid index.(HRESULT 异常:0x8002000B (DISP_E_BADINDEX)),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35862733/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com