none
render report to pdf RRS feed

  • Question

  •  I was able to render my report into pdf but then the report did not display the dataset. is there something missing in  my code? thnx

    LocalReport localReport = new LocalReport();

    SqlConnection conn = new SqlConnection("server=localhost;database=Northwind;Trusted_Connection=Yes");

    SqlDataAdapter adapter = new SqlDataAdapter();

    adapter.SelectCommand = new SqlCommand("select * from categories", conn);

    DataSet ds = new DataSet();

    adapter.Fill(ds);

    ReportDataSource reportDataSource = new ReportDataSource("CategoriesCollection",ds.Tables[0]);

    localReport.DataSources.Add(reportDataSource);

    localReport.ReportPath = "Report.rdlc";

    localReport.Refresh();





    string reportType = "PDF";

    string mimeType;

    string encoding;

    string fileNameExtension;

    string deviceInfo =

    "<DeviceInfo>" +

    " <OutputFormat>PDF</OutputFormat>" +

    " <PageWidth>8.5in</PageWidth>" +

    " <PageHeight>11in</PageHeight>" +

    " <MarginTop>0.5in</MarginTop>" +

    " <MarginLeft>1in</MarginLeft>" +

    " <MarginRight>1in</MarginRight>" +

    " <MarginBottom>0.5in</MarginBottom>" +

    "</DeviceInfo>";





    Warning[] warnings;

    string[] streams;

    byte[] renderedBytes;

    renderedBytes = localReport.Render(

    reportType,

    deviceInfo,

    out mimeType,

    out encoding,

    out fileNameExtension,

    out streams,

    out warnings);

    Response.Clear();

    Response.ContentType = mimeType;

    Response.AddHeader("content-disposition", "attachment; filename=foo." + fileNameExtension);

    Response.BinaryWrite(renderedBytes);

    Response.End();

    LocalReport localReport = new LocalReport();

    SqlConnection conn = new SqlConnection("server=localhost;database=Northwind;Trusted_Connection=Yes");

    SqlDataAdapter adapter = new SqlDataAdapter();

    adapter.SelectCommand = new SqlCommand("select * from categories", conn);

    DataSet ds = new DataSet();

    adapter.Fill(ds);

    ReportDataSource reportDataSource = new ReportDataSource("CategoriesCollection",ds.Tables[0]);

    localReport.DataSources.Add(reportDataSource);

    localReport.ReportPath = "Report.rdlc";

    localReport.Refresh();





     

    string reportType = "PDF";

    string mimeType;

    string encoding;

    string fileNameExtension;

    string deviceInfo =

    "<DeviceInfo>" +

    " <OutputFormat>PDF</OutputFormat>" +

    " <PageWidth>8.5in</PageWidth>" +

    " <PageHeight>11in</PageHeight>" +

    " <MarginTop>0.5in</MarginTop>" +

    " <MarginLeft>1in</MarginLeft>" +

    " <MarginRight>1in</MarginRight>" +

    " <MarginBottom>0.5in</MarginBottom>" +

    "</DeviceInfo>";





     

    Warning[] warnings;

    string[] streams;

    byte[] renderedBytes;

    renderedBytes = localReport.Render(

    reportType,

    deviceInfo,

    out mimeType,

    out encoding,

    out fileNameExtension,

    out streams,

    out warnings);

    Response.Clear();

    Response.ContentType = mimeType;

    Response.AddHeader("content-disposition", "attachment; filename=foo." + fileNameExtension);

    Response.BinaryWrite(renderedBytes);

    Response.End();



    -->

    Tuesday, October 21, 2008 4:02 AM

All replies

  • Does you report contain a DataSet with the name CategoriesCollection, if it doesn't then problem is most likely that the ReportViewer doesn't now what to bind the DataSet (ds) to in the report. The best way to find this is to open the Report.rdlc file with the XML editor in Visual Studio and search for the DataSet tag, you should have something similar to the following:

    <DataSets>
       <DataSet Name="CategoriesCollection">
          <Fields> ....

    This posting is provided "AS IS" with no warranties, and confers no rights.

    Wednesday, October 22, 2008 4:31 PM