报表处理过程中出现错误。 -RLDC在ASP.NET MVC报告 [英] An error occurred during report processing. -RLDC reporting in ASP.NET MVC

查看:204
本文介绍了报表处理过程中出现错误。 -RLDC在ASP.NET MVC报告的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这样的行动来生成报告:

 公众的ActionResult报告(字符串ID)
        {
            LocalReport LR =新LocalReport();
            字符串路径= Path.Combine(使用Server.Mappath(〜/报告),Person.rdlc);
            如果(System.IO.File.Exists(路径))
            {
                lr.ReportPath =路径;
            }
            其他
            {
                返回查看(「指数」);
            }
            清单<&人GT;厘米=新的List<&人GT;();            VAR视图模型=新PersonIndexData();            viewModel.People = db.Person
            .INCLUDE(K => k.Groups)
            .OrderBy(K => k.Name);            厘米= viewModel.People.ToList();            ReportDataSource RD =新ReportDataSource(PersonDataSet,厘米);
            lr.DataSources.Add(RD);
            字符串REPORTTYPE = ID;
            串mime类型;
            字符串编码;
            串fileNameExtension;            警告[]警告;
            字符串[]流;
            字节[] renderedBytes;            renderedBytes = lr.Render(
                报告类型,
                空值,
                出mime类型,
                出编码,
                出fileNameExtension,
                出流,
                出警告);
            返回文件(renderedBytes,mime类型);
        }

当我把这个动作是这样的:(mysite的/人/报告/ PDF),我得到这个异​​常:


  

报表处理过程中出错。
  指示该行:


  renderedBytes = lr.Render(
            报告类型,
            设备信息,
            出mime类型,
            出编码,
            出fileNameExtension,
            出流,
            出警告);

你能告诉我为什么我在这code得到此异常?它不给任何错误和异常不是很说明。我第一次使用EF-code。谢谢你。


解决方案

你有没有尝试这样添加一个TableAdapter后?这是工作完美的我。

 公共FileResult报告(字符串ID)
{
    PersonTableAdapter TA =新PersonTableAdapter();
    PersonDataSet DS =新PersonDataSet();    //避免未能启用约束。一行或多行中包含违反非空,唯一,或外键约束。错误
    ds.Person.Clear();
    ds.EnforceConstraints = FALSE;    ta.Fill(ds.Person,身份证); //你可以在这一步定制数据,即应用过滤器    ReportDataSource RDS =新ReportDataSource();
    rds.Name =ReportingDataSet;
    rds.Value = ds.Person;    RV的ReportViewer =新Microsoft.Reporting.WebForms.ReportViewer();
    rv.ProcessingMode = ProcessingMode.Local;
    rv.LocalReport.ReportPath =使用Server.Mappath(〜/报告/ Person.rdlc);    //新的报告数据源添加到报表。
    rv.LocalReport.DataSources.Add(RDS);
    rv.LocalReport.EnableHyperlinks = TRUE;
    rv.LocalReport.Refresh();    字节[] streamBytes = NULL;
    串mime类型=;
    字符串编码=;
    字符串filenameExtension =;
    字符串[] streamids = NULL;
    警告[]警告= NULL;    streamBytes = rv.LocalReport.Render(PDF,空,出mime类型,出编码,出来filenameExtension,出streamids,出警告);    返回文件(streamBytes,mime类型,人+_+编号+.PDF);
}

希望这有助于...

I have this action to generate reports :

  public ActionResult Report(string id)
        {
            LocalReport lr = new LocalReport();
            string path = Path.Combine(Server.MapPath("~/Report"), "Person.rdlc");
            if (System.IO.File.Exists(path))
            {
                lr.ReportPath = path;
            }
            else
            {
                return View("Index");
            }
            List<Person> cm = new List<Person>();

            var viewModel = new PersonIndexData();

            viewModel.People= db.Person
            .Include(k => k.Groups)
            .OrderBy(k => k.Name);

            cm = viewModel.People.ToList();

            ReportDataSource rd = new ReportDataSource("PersonDataSet", cm);
            lr.DataSources.Add(rd);
            string reportType = id;
            string mimeType;
            string encoding;
            string fileNameExtension;

            Warning[] warnings;
            string[] streams;
            byte[] renderedBytes;

            renderedBytes = lr.Render(
                reportType,
                null,
                out mimeType,
                out encoding,
                out fileNameExtension,
                out streams,
                out warnings);


            return File(renderedBytes, mimeType);
        }

When I call this action like this : (mysite/person/report/pdf), I get this exception :

An error occurred during report processing. Indicating this line :

        renderedBytes = lr.Render(
            reportType,
            deviceInfo,
            out mimeType,
            out encoding,
            out fileNameExtension,
            out streams,
            out warnings);

Can you tell me why I'm getting this exception in this code? It doesn't give any error and the exception is not very explanatory. I'm using EF-code first. Thank you.

解决方案

Have you try like this after adding a TableAdapter? It is working perfectly for me.

public FileResult Report(string id)
{
    PersonTableAdapter ta = new PersonTableAdapter();
    PersonDataSet ds = new PersonDataSet();

    //for avoiding "Failed to enable constraints. One or more rows contain values violating non-null, unique, or foreign-key constraints." error
    ds.Person.Clear();
    ds.EnforceConstraints = false;

    ta.Fill(ds.Person, id); //You might customize your data at this step i.e. applying a filter

    ReportDataSource rds = new ReportDataSource();
    rds.Name = "ReportingDataSet";
    rds.Value = ds.Person;

    ReportViewer rv = new Microsoft.Reporting.WebForms.ReportViewer();
    rv.ProcessingMode = ProcessingMode.Local;
    rv.LocalReport.ReportPath = Server.MapPath("~/Report/Person.rdlc");

    // Add the new report datasource to the report.
    rv.LocalReport.DataSources.Add(rds);
    rv.LocalReport.EnableHyperlinks = true;
    rv.LocalReport.Refresh();

    byte[] streamBytes = null;
    string mimeType = "";
    string encoding = "";
    string filenameExtension = "";
    string[] streamids = null;
    Warning[] warnings = null;

    streamBytes = rv.LocalReport.Render("PDF", null, out mimeType, out encoding, out filenameExtension, out streamids, out warnings);

    return File(streamBytes, mimeType, "Person" + "_" + id + ".pdf");
}

Hope this helps...

这篇关于报表处理过程中出现错误。 -RLDC在ASP.NET MVC报告的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆