.rdlc Report - Cannot create a data reader for dataset 'DataSet1'
Asked Answered
L

12

33

I have created a .rdlc-Report under VS 2012 using the report wizard and added data source and dataset. When I try to render the report using the code below I get following error message:

Cannot create a data reader for dataset 'DataSet1'.

bytes = localReport.Render("PDF", sdeviceinfo, out smimetype, out sencoding, out sfilenameextension, out streamids, out myWarnings);
Longfellow answered 12/3, 2013 at 15:46 Comment(0)
D
71

I have same problem that "Cannot create a data reader for dataset 'zzz'"

The answer is ReportDataSource(string xxx, DataTable yyy)

You should use the right name. xxx should be zzz

Deluca answered 11/6, 2013 at 2:51 Comment(3)
And don't forget to localReport.DataSources.Add() the ReportDataSource -- that was my issue.Winnifredwinning
But if xxx should be zzz, what about yyy? Should that be www?Toul
@Toul the yyy is the datatable which contains your columnsFauve
C
14

My 'gotcha' was the discovery that DataSet was not the same as Dataset.

Cower answered 15/5, 2015 at 18:31 Comment(1)
In my case it was that I was passing Dataset1 instead of DataSet1Ichnography
U
6

enter image description here

enter image description here

You have to give "DataSet1", otherwise it will not work.

Ulcer answered 7/9, 2018 at 23:52 Comment(1)
Datset and DataSet aren't same. Renaming properly will solve the error.Conviction
S
2

You unable to create ReportViewer and providing true dataset. It's possible you are getting the error due to parameter providing technique

You can try like this; I solved by using this way:

   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);
   



}
Singlehandedly answered 11/9, 2014 at 12:48 Comment(0)
A
2

Please Check Your DataSet Name Is Correct or not.

 reportDataSource = new ReportDataSource
    {
       Name = "DataSet1",// Check This Line. Are You Sure DataSet Name is Correct?
       Value = ListData 
    };
Aldous answered 11/3, 2019 at 10:56 Comment(1)
There were already numerous answers that said 'make sure your name is correct'. Please only add answers when you have something new to add.Gardy
O
1
  1. Make sure that you are running on administrator mode and you have access to the SSRS server.

  2. Verify if you have set the correct dataset name or if you are properly loading and assigning it.

Please check this sample on MSDN.

Occidental answered 12/3, 2013 at 17:14 Comment(0)
I
1

For my case, I didn't set name for my ReportDataSource. Following resolved my problem:

oRptDataSource5.Name = "ExtraCoverage"

Good luck!

Invert answered 5/9, 2023 at 19:19 Comment(0)
I
0

I solved the problem -- my coding error -- I had omitted 'proper' parameter values from the aspx code for the SqlServerDataSource as follows...

Notice there is NO DefaultValue for parameter-name="p_CSV_VEHICLES"

AND (it turned out) that the two parameters (="p_CSV_VGROUPS" and ="p_CSV_VEHICLES") could not pass an empty-string "" as the default value -- empty-string is invalid in the select context for these two parameters.

After I added the DefaultValue and set the DefaultValue(s) to valid string values for each parameter, the report showed perfectly in the ReportViewer control on my web-page.

Here is the original (not working) aspx-code.

     <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>
Infection answered 28/12, 2015 at 22:55 Comment(0)
N
0

I also had the same problem. After my observations I identified that, the RDLC reports does need the dataset either it should has some records in it or empty object(empty object will have the meta data)

So best practice is always return a dataset with empty object (not Null or nothing)or with some records in it.

Nicaea answered 12/7, 2017 at 12:28 Comment(0)
S
0
reportviewer1.LocalReport.DataSources.Add(New ReportDataSource("DataSet1", ObjectDataSource1))

it's better you post your code how you set your datasource to the report.

Slattern answered 18/7, 2017 at 1:39 Comment(0)
S
0

Be sure these two things are be Ok:

1) in Report1.rdlc[Design] (press Alt+Ctrl+D):

RightClick on Datasets and add dataset,

in the Dataset properties form, choose name :DataSet1

click on New... button next to the DataSource combocox

click on Object

on your project. select yourList1 or ...

and Finish.

now select Datasource and Available datasets on comboboxes.

repeat these steps and create DataSet2 ...

click OK and close the form.

2) in yourFormPrint code:

    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);
    }
Slaver answered 7/7, 2019 at 4:58 Comment(0)
W
0

I cannot share the source code, but I wanted to submit an answer that helped me.

I copied a previously made report from the existing codebase. It already had the Datasets created in the 'Report Data' view in Visual Studio because I copied an existing report. I needed the bulk of this pre-existing report; however, I deleted one of the Datasets and replaced it with a new one I created that housed the new data I needed for the new report.

The big mistake I made here is that I thought I re-named the new Dataset that I made to the same exact name of the old Dataset. The old Dataset was named "ReportDetail". However, the new one I made was named "ReportDetails" with an "s".

I needed some of the data fields from the old Dataset; however, I did not realize those old fields were still in the copied report under the old Dataset name. So in the report there was a field still being called "ReportDetail.{fieldName}". This was ultimately what was calling the issue.

Once I opened the XML version of the .rdlc report I was clearly able to see that the old Dataset name was still being used. Since that old Dataset didn't exist any more it was throwing this error. Once I flipped the field to utilize the new Dataset name it worked correctly.

Whitesell answered 13/1, 2021 at 19:50 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.