C# .rdlc报告-无法为数据集“DataSet1”创建数据读取器

C# .rdlc报告-无法为数据集“DataSet1”创建数据读取器,c#,.net,reporting-services,visual-studio-2012,report,C#,.net,Reporting Services,Visual Studio 2012,Report,我使用报告向导在VS 2012下创建了一个.rdlc报告,并添加了数据源和数据集。 当我尝试使用下面的代码呈现报告时,会收到以下错误消息: 无法为数据集“DataSet1”创建数据读取器 确保您在管理员模式下运行,并且您有权访问SSRS服务器 验证是否设置了正确的数据集名称,或者是否正确加载和分配了数据集名称 请检查MSDN上的示例。我遇到了无法为数据集“zzz”创建数据读取器的相同问题 答案是ReportDataSourcestring xxx,DataTable yyy 你应该使用正确的名字

我使用报告向导在VS 2012下创建了一个.rdlc报告,并添加了数据源和数据集。 当我尝试使用下面的代码呈现报告时,会收到以下错误消息:

无法为数据集“DataSet1”创建数据读取器

确保您在管理员模式下运行,并且您有权访问SSRS服务器

验证是否设置了正确的数据集名称,或者是否正确加载和分配了数据集名称


请检查MSDN上的示例。

我遇到了无法为数据集“zzz”创建数据读取器的相同问题

答案是ReportDataSourcestring xxx,DataTable yyy


你应该使用正确的名字。xxx应该是zzz

您无法创建ReportViewer并提供真实的数据集。可能是由于参数提供技术导致了错误

你可以这样试试;我用这种方法解决了这个问题:

   protected void btnPdf_Click(object sender, EventArgs e)
    {
    ReportViewer viwer = new ReportViewer();
    ObjectDataSource ob = new ObjectDataSource("dataset.YourTableAdapter", "GetData");
    dataset.YourTableAdapter ds = new dataset.YourTableAdapter();

    string PDF = "PDF";
    string ReportType = "ReportType";
    Warning[] warnings = null;
    string[] streamIds = null;
    string mimeType = string.Empty;
    string encoding = string.Empty;
    string extension = string.Empty;
    string filetype = string.Empty;

   

    viwer.SizeToReportContent = true;
    viwer.LocalReport.ReportPath = "reports/report/report.rdlc";
    viwer.ProcessingMode = ProcessingMode.Local;
    ob.SelectParameters.Clear();
    ob.SelectParameters.Add(QueryStringEnum.CompanyID, CurrentCompanyID.ToString());
 
    ReportDataSource rds = new ReportDataSource("datasetname", (object) ds.GetData((long?)CurrentCompanyID.ToInt64());

    viwer.LocalReport.DataSources.Add(rds);
    viwer.LocalReport.Refresh();

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



}

我的“发现”是发现DataSet与DataSet不同。

我解决了这个问题-我的编码错误-我从SqlServerDataSource的aspx代码中省略了“正确”参数值,如下所示

请注意,参数name=p_CSV_VEHICLES没有默认值

事实证明,这两个参数=p_CSV_VGROUPS和=p_CSV_VEHICLES无法传递空字符串,因为默认值-空字符串在这两个参数的选择上下文中无效

在添加DefaultValue并为每个参数将DefaultValue设置为有效的字符串值后,报告在我的网页上的ReportViewer控件中完美地显示出来

这是原始的不工作的aspx代码

     <asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:FCI_WebMainConnectionString %>" 
        SelectCommand="uspRPT_CostDetailFleet" SelectCommandType="StoredProcedure">
        <SelectParameters>
           <asp:Parameter DefaultValue="5" Name="p_UID_DIVISION" Type="Int32" />
           <asp:Parameter DefaultValue="85" Name="p_UID_CUSTOMER" Type="Int32" />
           <asp:Parameter DefaultValue="FCIFLEETGRP" Name="p_SORT_ORDER" Type="String" />
           <asp:Parameter DefaultValue="" Name="p_CSV_VGROUPS" Type="String" />
           <asp:Parameter Name="p_CSV_VEHICLES" Type="String" />
           <asp:Parameter DbType="Date" DefaultValue="#01/01/2013#" Name="p_dtStart0" />
           <asp:Parameter DbType="Date" DefaultValue="#12/31/2013#" Name="p_dtEnd0" />
        </SelectParameters>
     </asp:SqlDataSource>

我也有同样的问题。在我观察之后,我发现RDLC报告确实需要数据集,要么它应该有一些记录,要么空对象空对象将有元数据

因此,最佳实践是始终返回一个数据集,其中包含空对象NOTNULL或NOTHING,或者其中包含一些记录

reportviewer1.LocalReport.DataSources.Add(New ReportDataSource("DataSet1", ObjectDataSource1))
最好将您的代码发布到如何将数据源设置到报表中


您必须提供数据集1,否则它将不起作用。

请检查您的数据集名称是否正确

 reportDataSource = new ReportDataSource
    {
       Name = "DataSet1",// Check This Line. Are You Sure DataSet Name is Correct?
       Value = ListData 
    };

确保这两件事都很好:

报告中的1。rdlc[设计]按Alt+Ctrl+D:

右键单击数据集并添加数据集

在数据集属性窗体中,选择名称:DataSet1

点击新建。。。数据源组合框旁边的按钮

单击对象

关于你的项目。选择您的列表1或

然后结束

现在选择组合框上的数据源和可用数据集

重复这些步骤并创建数据集2

单击“确定”并关闭表单

2在您的表单打印代码中:

    private void frmPrint_Load(object sender, EventArgs e)
    {
        CreateReport1();
        System.Drawing.Printing.PageSettings ps = new 
               System.Drawing.Printing.PageSettings();
        ps.Margins.Top = CentimeterToPixel(0.9);
        ps.Margins.Left = CentimeterToPixel(0.9);
        ps.Margins.Right = CentimeterToPixel(0.9);
        ps.Margins.Bottom = CentimeterToPixel(0.9);
        ps.Landscape = false;
        ps.PaperSize =new PaperSize ("A4", 827, 1169);
        ps.PaperSize.RawKind = (Int32)(System.Drawing.Printing.PaperKind.A4);
        //psize.RawKind = (int)PaperKind.A4;
        //ps.PaperSize = psize;
        reportViewer1.SetPageSettings(ps);
        this.reportViewer1.RefreshReport();
        this.reportViewer1.SetDisplayMode(DisplayMode.PrintLayout);
        WindowState = FormWindowState.Maximized;
    }
    private int CentimeterToPixel(double Centimeter)
    {
        int  pixel = -1;
        using (Graphics g = this.CreateGraphics())
        {
            pixel =Convert.ToInt32 ( Centimeter * (g.DpiY / 2.54));
        }
        return pixel;
    }
    private void CreateReport1()
    {
        reportViewer1.LocalReport.DataSources.Clear();
        reportViewer1.ProcessingMode = 
                     Microsoft.Reporting.WinForms.ProcessingMode.Local;


        reportViewer1.LocalReport.ReportEmbeddedResource = 
                        "yourProjectName.Report1.rdlc";
        ReportDataSource RDS = new ReportDataSource();
        RDS.Name = "DataSet1";
        RDS.Value = yourPublicList1;
        reportViewer1.LocalReport.DataSources.Add(RDS);

        ReportDataSource RDS2 = new ReportDataSource();
        RDS2.Name = "DataSet2";
        RDS2.Value = yourPublicList2;
        reportViewer1.LocalReport.DataSources.Add(RDS2);
    }

我不能分享源代码,但我想提交一个帮助我的答案

我从现有的代码库复制了一份以前制作的报告。它已经在VisualStudio的“Report Data”视图中创建了数据集,因为我复制了一个现有的报表。 我需要这份已经存在的报告的大部分;但是,我删除了其中一个数据集,并将其替换为我创建的一个新数据集,该数据集包含了新报告所需的新数据

我在这里犯的一个大错误是,我认为我重新命名了新的数据集,并将其命名为与旧数据集完全相同的名称。旧数据集名为ReportDetail。然而,我制作的新版本名为ReportDetails,带有s

我需要旧数据集中的一些数据字段;但是,我没有意识到这些旧字段仍然以旧数据集名称存在于复制的报表中。所以在报告中有一个字段仍然被称为ReportDetail。{fieldName}。这就是所谓的问题


打开.rdlc报告的XML版本后,我清楚地看到旧的数据集名称仍在使用。因为那个旧数据集已经不存在了,所以它抛出了这个错误。一旦我翻转字段以使用新的数据集名称,它就会正常工作。

不要忘记localReport.DataSources.Add ReportDataSource-这是我的问题。但是如果xxx应该是zzz,那么yyy呢?这应该是www@Rich吗?yyy是包含您的列的数据表。数据集和数据集不一样。正确重命名将解决此错误。已经有很多答案说“确保您的名字正确”。请仅在您有新内容要添加时添加答案。在我的情况下,我传递的是Dataset1而不是Dataset1
    private void frmPrint_Load(object sender, EventArgs e)
    {
        CreateReport1();
        System.Drawing.Printing.PageSettings ps = new 
               System.Drawing.Printing.PageSettings();
        ps.Margins.Top = CentimeterToPixel(0.9);
        ps.Margins.Left = CentimeterToPixel(0.9);
        ps.Margins.Right = CentimeterToPixel(0.9);
        ps.Margins.Bottom = CentimeterToPixel(0.9);
        ps.Landscape = false;
        ps.PaperSize =new PaperSize ("A4", 827, 1169);
        ps.PaperSize.RawKind = (Int32)(System.Drawing.Printing.PaperKind.A4);
        //psize.RawKind = (int)PaperKind.A4;
        //ps.PaperSize = psize;
        reportViewer1.SetPageSettings(ps);
        this.reportViewer1.RefreshReport();
        this.reportViewer1.SetDisplayMode(DisplayMode.PrintLayout);
        WindowState = FormWindowState.Maximized;
    }
    private int CentimeterToPixel(double Centimeter)
    {
        int  pixel = -1;
        using (Graphics g = this.CreateGraphics())
        {
            pixel =Convert.ToInt32 ( Centimeter * (g.DpiY / 2.54));
        }
        return pixel;
    }
    private void CreateReport1()
    {
        reportViewer1.LocalReport.DataSources.Clear();
        reportViewer1.ProcessingMode = 
                     Microsoft.Reporting.WinForms.ProcessingMode.Local;


        reportViewer1.LocalReport.ReportEmbeddedResource = 
                        "yourProjectName.Report1.rdlc";
        ReportDataSource RDS = new ReportDataSource();
        RDS.Name = "DataSet1";
        RDS.Value = yourPublicList1;
        reportViewer1.LocalReport.DataSources.Add(RDS);

        ReportDataSource RDS2 = new ReportDataSource();
        RDS2.Name = "DataSet2";
        RDS2.Value = yourPublicList2;
        reportViewer1.LocalReport.DataSources.Add(RDS2);
    }