4,816
社区成员
发帖
与我相关
我的任务
分享
“/报表打印测试”应用程序中的服务器错误。
--------------------------------------------------------------------------------
拒绝访问。
说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。
异常详细信息: System.Runtime.InteropServices.COMException: 拒绝访问。
源错误:
执行当前 Web 请求期间生成了未处理的异常。可以使用下面的异常堆栈跟踪信息确定有关异常原因和发生位置的信息。
堆栈跟踪:
[COMException (0x80004005): 拒绝访问。
]
using System;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
viewCrystalReport();
}
}
protected void viewCrystalReport()
{
//生成测试数据
DataTable dt = this.getReportData();
//载入设计好的报表到报表源
this.crSource.Report.FileName = Server.MapPath("report_fjljcnyxhbb.rpt");
//将数据绑定
this.crSource.ReportDocument.SetDataSource(dt);
//设置自定义参数
this.crSource.ReportDocument.SetParameterValue("txt_jvname", "xx铁路局");
this.crSource.ReportDocument.SetParameterValue("txt_duanName", "xx段");
this.crSource.ReportDocument.SetParameterValue("txt_date", DateTime.Now.Year.ToString() + "年" + DateTime.Now.Month.ToString() + "月");
//显示报表
this.crView.ReportSourceID = "crSource";
}
private DataTable getReportData()
{
//生成临时表
DataTable dt = new DataTable();
//表名称,随便写
dt.TableName = "myTable";
//这里的列名称,一定要跟 对应的xsd ,这里就是 xsd_fjljcnyxhbb_Ds.xsd 的列名一致。否则绑定不上
dt.Columns.Add("jx", System.Type.GetType("System.String"));
dt.Columns.Add("yszb", System.Type.GetType("System.String"));
for (int i = 0; i < 19; i++)
{
DataRow dr = dt.NewRow();
dr["jx"] = "机型" + (i+1);
dr["yszb"] = "种别" + (i+1);
dt.Rows.Add(dr);
}
return dt;
}
}