RDLC 报告错误
RDLC Report Error
我对 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>
我总是得到这个错误:
"An error occurred during local report processing."
有人可以帮我说说我做错了什么吗?
谢谢!!
问题是因为您的数据集名称不正确。
内部异常是 -> "Cannot create a data reader for dataset 'DataSet_Reservaties'."
这里的根本错误是在这个语句中第一个参数应该匹配数据集的名称 -
ReportDataSource rds = new ReportDataSource("Reservaties", ds.Tables[0]);
将代码更改为以下内容后,它应该可以工作。
ReportDataSource rds = new ReportDataSource("DataSet_Reservaties", ds.Tables[0]);
我对 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>
我总是得到这个错误:
"An error occurred during local report processing."
有人可以帮我说说我做错了什么吗?
谢谢!!
问题是因为您的数据集名称不正确。
内部异常是 -> "Cannot create a data reader for dataset 'DataSet_Reservaties'."
这里的根本错误是在这个语句中第一个参数应该匹配数据集的名称 -
ReportDataSource rds = new ReportDataSource("Reservaties", ds.Tables[0]);
将代码更改为以下内容后,它应该可以工作。
ReportDataSource rds = new ReportDataSource("DataSet_Reservaties", ds.Tables[0]);