2

我使用 Report Builder 3.0 构建了一个报表,并尝试在 VS 2010 中使用报表查看器显示它。我不断收到此错误消息。

报告定义无效。详细信息:报表定义具有无法升级的无效目标命名空间“http://schemas.microsoft.com/sqlserver/reporting/2010/01/reportdefinition”。

这是我正在使用的代码。

public partial class ViewReport : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if(!IsPostBack)
            PopulateReport(GetDataSet("24"), Server.MapPath("/IncidentReportOld.rdl"));
    }
    private DataSet GetDataSet(string id)
    {
        string sql = string.Empty;
        SqlDataAdapter ada;
        string conString = "Data Source=con-sqlc-02;Initial Catalog=Incident;Integrated Security=True";

        DataSet ds = new DataSet();

        sql = "select * from Rpt_Incident where incidentID = " + id;
        ada = new SqlDataAdapter(sql, conString);
        ada.Fill(ds, "Incidents");

        return ds;
    }

    private void PopulateReport(DataSet ds, string reportPath)
    {
        /* Put the stored procedure result into a dataset */

        if (ds.Tables[0].Rows.Count == 0)
        {
            //lblMessage.Text = "Sorry, no record returned in this report";
        }
        else
        {

            // Set ReportViewer1
            ReportViewer rv = new ReportViewer();
            rv.LocalReport.ReportPath = reportPath;
            ReportDataSource datasource;
            rv.LocalReport.DataSources.Clear();
            for (int i = 0; i < ds.Tables.Count; i++)
            {
                datasource = new ReportDataSource(ds.Tables[i].TableName, ds.Tables[i]);
                rv.LocalReport.DataSources.Add(datasource);
            }

            RenderPDF(rv);
        }
    }

    private void RenderPDF(ReportViewer rv)
    {
        Warning[] warnings;
        string[] streamids;
        string mimeType;
        string encoding;
        string extension;

        byte[] bytes = rv.LocalReport.Render("PDF", null, out mimeType, out encoding, out extension, out streamids, out warnings);

        this.Page.Response.ClearHeaders();
        this.Page.Response.AddHeader("content-disposition", "inline; filename=IncidentTest.pdf");
        this.Page.Response.ClearContent();
        this.Page.Response.ContentEncoding = System.Text.Encoding.UTF8;
        this.Page.Response.ContentType = "application/pdf";

        BinaryWriter writer = new BinaryWriter(this.Page.Response.OutputStream);
        writer.Write(bytes);

        writer.Close();

        //flush and close the response object
        this.Page.Response.Flush();
        this.Page.Response.Close();
    }
    private void PopulateReport1(DataSet ds, string reportPath)
    {
        /* Put the stored procedure result into a dataset */

        if (ds.Tables[0].Rows.Count == 0)
        {
            //lblMessage.Text = "Sorry, no record returned in this report";
        }
        else
        {

            // Set ReportViewer1
            //ReportViewer rv = new ReportViewer();
            ReportViewer1.LocalReport.ReportPath = reportPath;
            ReportDataSource datasource;
            ReportViewer1.LocalReport.DataSources.Clear();
            for (int i = 0; i < ds.Tables.Count; i++)
            {
                datasource = new ReportDataSource(ds.Tables[i].TableName, ds.Tables[i]);
                ReportViewer1.LocalReport.DataSources.Add(datasource);
            }

            ReportViewer1.LocalReport.Refresh();
            //RenderPDF(rv);
        }
    }


}
4

3 回答 3

6

我实际上能够自己解决这个问题。

我刚刚将扩展名从 RDL 更改为 RDLC。然后我在VS中打开它,VS问我是否要转换它。我说是的,然后我收到了此错误消息。

报表定义具有无法升级的无效目标命名空间“http://schemas.microsoft.com/sqlserver/reporting/2010/01/reportdefinition”。

所以我将命名空间更改为用于 SQL Reporting Services 2008 的命名空间。

<Report xmlns:rd="http://schemas.microsoft.com/SQLServer/reporting/reportdesigner" xmlns="http://schemas.microsoft.com/sqlserver/reporting/2008/01/reportdefinition">

之后我收到一条错误消息,说“ReportSections”是一个无效的子元素。我删除了它,然后一切正常!希望这将帮助其他人解决这个问题。

于 2011-04-14T20:38:34.440 回答
1

我在我的 winforms 项目中解决了这个问题,方法是在 References中更改Microsoft.ReportViewer.CommonMicrosoft.ReportViewer.WinFormsto的特定版本属性false

于 2012-02-01T20:07:23.067 回答
0

我遇到了同样的问题,但你的解决方案对我不起作用。我正在使用 VS 2013 express 并使用 ReportBuilder 3.0。我在 msdn 论坛上看到使用 ReportBuilder2.0 可以解决这个问题,他们是对的。所以尝试使用 Report Builder 2.0。

于 2014-05-01T06:46:12.577 回答