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 e
Showing error cannot create data reader for data set of dataset1:
private void frm_report_Load(object sender, EventArgs e)
{
this.reportViewer1.RefreshReport();
reportViewer1.LocalReport.Refresh();
reportViewer1.LocalReport.DataSources.Clear();
reportViewer1.LocalReport.ReportEmbeddedResource = "cruds_reports.Report1.rdlc";
SqlCommand cmd = new SqlCommand("select * from tbl_info",con);
SqlDataAdapter da = new SqlDataAdapter();
DataSet ds = new DataSet();
da.Fill(ds);
DataTable dt = new DataTable();
dt = ds.Tables[0];
if (dt.Rows.Count>0)
{
rds = new ReportDataSource("DataSet1", dt);
reportViewer1.LocalReport.DataSources.Add(rds);
rds.Value = dt;
reportViewer1.LocalReport.Refresh();
reportViewer1.RefreshReport();
}
else
{
return;
}
}
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);
}
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
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);
}
My 'gotcha' was the discovery that DataSet was not the same as Dataset.
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.