c# - Report Viewer export to pdf getting error -
i getting error "cannot create data reader dataset 'dataset1'."
i expend lots of time solving issue unable resolved.same code working report generation @ time of pdf generation stuck.
here code please reply.
protected void btnpdf_click(object sender, eventargs e) { 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; long _landids = 0; if (_farmid > 0) { land land = landmanager.getlandbyfarmid(_farmid); _landids = land.landid; } reportviewer_myreportid.sizetoreportcontent = true; reportviewer_myreportid.localreport.reportpath = "reports/report/report.rdlc"; reportviewer_myreportid.processingmode = processingmode.remote; objectdatasource_id.selectparameters.clear(); objectdatasource_id.selectparameters.add(querystringenum.companyid, currentcompanyid.tostring()); objectdatasource_id.selectparameters.add(querystringenum.landid, _landids.tostring()); var days = "-" + rdduration.selectedvalue; objectdatasource_id.selectparameters.add(querystringenum.days, days.tostring()); reportviewer_myreportid.localreport.refresh(); byte[] bytes = reportviewer_myreportid.localreport.render("pdf", null, out mimetype, out encoding, out extension, out streamids, out warnings); filestream fs = new filestream(server.mappath("~/generatedfiles/" + reporttype + "." + "pdf"), filemode.openorcreate); fs.write(bytes, 0, bytes.length); fs.close(); }
it work you.make sure dataset name not different.
code reference.
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; long _landids = 0; if (_farmid > 0) { land land = landmanager.getlandbyfarmid(_farmid); _landids = land.landid; } viwer.sizetoreportcontent = true; viwer.localreport.reportpath = "reports/report/report.rdlc"; viwer.processingmode = processingmode.local; ob.selectparameters.clear(); ob.selectparameters.add(querystringenum.companyid, currentcompanyid.tostring()); ob.selectparameters.add(querystringenum.landid, _landids.tostring()); var days = "-" + rdduration.selectedvalue; ob.selectparameters.add(querystringenum.days, days.tostring()); reportdatasource rds = new reportdatasource("datasetname", (object) ds.getdata((long?)currentcompanyid.toint64(), (int?)days.toint(), (long?)_landids.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); filestream fs = new filestream(server.mappath("~/generatedfiles/" + reporttype + "." + "pdf"), filemode.openorcreate); fs.write(bytes, 0, bytes.length); fs.close(); }
Comments
Post a Comment