RDLC报告错误

我对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>

我总是收到此错误:


“本地报告处理期间发生错误。”


有人可以帮我告诉我我做错了吗?


莫回无
浏览 328回答 1
1回答

紫衣仙女

问题是因为您的数据集名称不正确。Innerexception为->“无法为数据集'DataSet_Reservaties'创建数据读取器。”此处的基本错误是,在此语句中,第一个参数应与数据集的名称匹配-ReportDataSource&nbsp;rds&nbsp;=&nbsp;new&nbsp;ReportDataSource("Reservaties",&nbsp;ds.Tables[0]);将代码更改为以下代码后,它应该可以工作。ReportDataSource&nbsp;rds&nbsp;=&nbsp;new&nbsp;ReportDataSource("DataSet_Reservaties",&nbsp;ds.Tables[0]);
打开App,查看更多内容
随时随地看视频慕课网APP