我对RDLC报告有问题。我的报告可以转换为PDF。我的控制器中有以下代码:private DataSet GetDataSet() { MySqlConnection connection = null; string connstring = string.Format("Server=myWebsite.com;user id=myUsername;password=myPassword;persist security info=True;database=myDatabase"); connection = new MySqlConnection(connstring); connection.Open(); string sql = string.Format("Select * FROM Reservaties"); MySqlDataAdapter ad = new MySqlDataAdapter(sql, connstring); DataSet ds = new DataSet(); ad.Fill(ds); return ds; } public ActionResult Reports(string ReportType) { LocalReport localreport = new LocalReport(); localreport.ReportPath = Server.MapPath("~/Reports/Report_Reservatie.rdlc"); DataSet ds = GetDataSet(); ReportDataSource rds = new ReportDataSource("Reservaties", ds.Tables[0]); localreport.DataSources.Add(rds); string reportType = ReportType; string mimeType; string encoding; string fileNameExtension; if (reportType == "PDF") { fileNameExtension = "pdf"; } else { fileNameExtension = "jpg"; } string[] streams; Warning[] warnings; byte[] renderedByte; renderedByte = localreport.Render(reportType, "", out mimeType, out encoding, out fileNameExtension, out streams, out warnings); Response.AddHeader("content-disposition", "attachment:filename + reservaties_report." + fileNameExtension); return File(renderedByte, fileNameExtension); }这是我的观点:@model int@{ViewBag.Title = "Checkout Complete";}<h2>@HojapaApplication.Resources.ResourceNL.CheckoutComplete</h2><p>@HojapaApplication.Resources.ResourceNL.ThankForTheOrder: @Model</p>@Html.ActionLink("Export to PDF", "Reports", new { ReportType = "PDF"}, null)<p> @HojapaApplication.Resources.ResourceNL.MoreShoppingOrNot @Html.ActionLink("store","Index", "Home")</p>我总是收到此错误:“本地报告处理期间发生错误。”有人可以帮我告诉我我做错了吗?
1 回答
紫衣仙女
TA贡献1839条经验 获得超15个赞
问题是因为您的数据集名称不正确。
Innerexception为->“无法为数据集'DataSet_Reservaties'创建数据读取器。”
此处的基本错误是,在此语句中,第一个参数应与数据集的名称匹配-
ReportDataSource rds = new ReportDataSource("Reservaties", ds.Tables[0]);
将代码更改为以下代码后,它应该可以工作。
ReportDataSource rds = new ReportDataSource("DataSet_Reservaties", ds.Tables[0]);
- 1 回答
- 0 关注
- 327 浏览
添加回答
举报
0/150
提交
取消