在rdlc中创建没有报表查看器的Pdf [英] Creating Pdf without report viewer in rdlc
本文介绍了在rdlc中创建没有报表查看器的Pdf的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
嘿
我正在研究rdlc报告我的页面上有一个按钮,当点击它时,pdf显示的不是报告查看器中的报告。它工作正常但是当我添加参数报告时它在报表查看器中运行良好pdf也会生成但是当我尝试生成没有报表查看器代码的pdf时会出现错误:本地报表处理时出错。
给出的代码下面:
Hey
I am working on rdlc reports I have a button on my page and when this is clicked pdf is shown not the report in report viewer.It works fine but when i add parameters to report it works well in report viewer pdf is also generated but when i try to generate pdf without report viewer code gives error: An error ocuured while local report processing.
Code given below:
private void CreatePDF(string id, string pid)
{
string issalaried = "";
DataSet DsRep = getemplyeebasicdetail(id, pid);
DataSet dssalaryDetails = getemplyeesalarydetail(id, pid);
DataSet dsEmployeeCount = GetEmplyoeeCount(id, pid);
int rowcount = dssalaryDetails.Tables[0].Rows.Count;
if (rowcount == 0)
{
DataRow dr = dssalaryDetails.Tables[0].NewRow();
dssalaryDetails.Tables[0].Rows.Add(dr);
}
else
{
Boolean salaried = false;
foreach (DataRow dr in dssalaryDetails.Tables[0].Rows)
{
if (dr["issalaried"].ToString() == "Y")
{
salaried = true;
}
}
if (salaried == false)
{
issalaried = "N";
}
else
{
issalaried = "Y";
}
}
ReportDataSource datasource = new ReportDataSource("DS1", DsRep.Tables[0]);
ReportDataSource datasourcefamily = new ReportDataSource("DS2", dssalaryDetails.Tables[0]);
ReportDataSource datasourcecount = new ReportDataSource("DS3", dsEmployeeCount.Tables[0]);
ReportParameter[] Param = new ReportParameter[1];
Param[0] = new ReportParameter("Param_IsSalaried", issalaried);
Warning[] warnings;
string[] streamIds;
string mimeType = string.Empty;
string encoding = string.Empty;
string extension = string.Empty;
// Setup the report viewer object and get the array of bytes
ReportViewer viewer = new ReportViewer();
viewer.ProcessingMode = ProcessingMode.Local;
viewer.LocalReport.ReportPath = Server.MapPath("~\\Employee.rdlc");
//Datasource
viewer.LocalReport.DataSources.Add(datasource);
viewer.LocalReport.SetParameters(Param);
viewer.LocalReport.EnableExternalImages = true;
byte[] bytes = viewer.LocalReport.Render("PDF", null, out mimeType, out encoding, out extension, out streamIds, out warnings);
// Now that you have all the bytes representing the PDF report, buffer it and send it to the client.
Response.Buffer = true;
Response.Clear();
Response.ContentType = mimeType;
Response.AddHeader("content-disposition", "attachment; filename=" + "Employee" + "." + extension);
Response.BinaryWrite(bytes); // create the file
Response.Flush(); // send it to the client to download
//Page settings for PDF File.
}
推荐答案
InnerException是否提供更好的错误消息?
Does the InnerException give a better error message?
这篇关于在rdlc中创建没有报表查看器的Pdf的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文