我的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>
我总是收到这个错误:
&#34;本地报告处理过程中出错。&#34;
有人可以帮我说出我做错了吗?
THX !!
答案 0 :(得分:0)
问题是因为您的数据集名称不正确。
Innerexception是 - &gt; &#34;无法为数据集创建数据读取器&#39; DataSet_Reservaties&#39;。&#34;
这里的根本错误是,在此语句中,第一个参数应与数据集的名称匹配 -
ReportDataSource rds = new ReportDataSource("Reservaties", ds.Tables[0]);
&#13;
将代码更改为以下代码后,它应该可以正常工作。
ReportDataSource rds = new ReportDataSource("DataSet_Reservaties", ds.Tables[0]);
&#13;