Click here to Skip to main content
15,891,253 members
Please Sign up or sign in to vote.
3.50/5 (2 votes)
See more:
I tried hard and search on google but I am unable to export rdls report to pdf/ excel direclty.An exception occured
Please help me.

I have created report from wizard.Report.rdlc
now i am using the code as
C#
byte[] bytes = null;
	string strDeviceInfo = "";
	string strMimeType = "";
	string strEncoding = "";
	string strExtension = "";
	string[] strStreams = null;
	Warning[] warnings = null;
	
    try
    {
        ReportDataSource rds = new ReportDataSource("f_MANPOWERREQUISITION");
        ReportViewer rptViewer1 = new ReportViewer();
        rptViewer1.ProcessingMode = ProcessingMode.Local;
        rptViewer1.LocalReport.ReportPath = Server.MapPath("Report.rdlc");
        bytes = rptViewer1.LocalReport.Render(strFormat, strDeviceInfo, out strMimeType, out  strEncoding, out strExtension, out strStreams, out warnings);
        Response.Buffer = true;
        Response.Clear();
        Response.ContentType = strMimeType;
        Response.AddHeader("content-disposition", "attachment; filename=" + strNomFichier + "." + strFormat);
        Response.BinaryWrite(bytes); // create the file
        Response.Flush();
    }// send it to the client to download
    catch (Exception ex)
    {
    }

Inner Exception:A data source instance has not been supplied for the data source \"DataSet2_f_MANPOWERREQUISITION\".
Posted
Updated 4-Nov-11 0:37am
v2

This can help out..
Try once..
=======================================================
C#
private void CreatePDF(string fileName)
{
    // Variables
    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 = "YourReportHere.rdlc";


    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=" + fileName + "." + extension);
    Response.BinaryWrite(bytes); // create the file
    Response.Flush(); // send it to the client to download
}
 
Share this answer
 
Comments
Sandeep Mewara 4-Sep-12 2:09am    
Try once after 8 months?
amir mansour 12-May-15 2:51am    
Can you please tell me what namespaces that you added and its references ?
it says Response is not exist in the current context !!
What is happening her is that you can not bind the table adapter to the report.

You need to bind a data table to the report.

Try something along the lines of the following:
C#
DataSet2TableAdapters.f_MANPOWERREQUISITIONTableAdapter  ta = new DataSet2TableAdapters.f_MANPOWERREQUISITIONTableAdapter  ();

DataSet2_f_MANPOWERREQUISITION.TheTableInYourDataSet  dt = new DataSet2_f_MANPOWERREQUISITION.TheTableInYourDataSet();

ta.Fill(dt);
 
ReportDataSource rds = new ReportDataSource("DataSet2_f_MANPOWERREQUISITION",dt);


If "DataSet2_f_MANPOWERREQUISITION" gives you an error open the RDLC in N++ or a similar Text Editor and search for "<dataset name=" nad replace " dataset2_f_manpowerrequisition=" with the DatSet name in your RDLC</xml>">
 
Share this answer
 
v3
The error that you receive explicitly tells you what is going wrong.

The name that you are using to create the reportDatasource does not match with the name in the DataSet definition in your rdlc.

I also do not see the actual data being asigned to the DataSource.

Try using

ReportDataSource rds = new ReportDataSource("DataSet2_f_MANPOWERREQUISITION","could be a data table or something with the data tha needs in the report");
 
Share this answer
 
Comments
uspatel 4-Nov-11 7:18am    
Thanks for reply.
A DataSet DataSet2 created when i create Report.rdlc.
when i tried to provide 2nd argument as
ReportDataSource rds = new ReportDataSource("DataSet2_f_MANPOWERREQUISITION",DataSet2TableAdapters.f_MANPOWERREQUISITIONTableAdapter)

It shows an error as

Error 1 'DataSet2TableAdapters.f_MANPOWERREQUISITIONTableAdapter' is a 'type', which is not valid in the given context C:\Documents and Settings\shubhamanand\My Documents\Visual Studio 2008\WebSites\WebSite10\Default.aspx.cs 40 112 C:\...\WebSite10\
can you please tell me what header you used fro response
???
 
Share this answer
 
Comments
Deepu S Nair 11-May-15 2:48am    
Don't post your comment as soution.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900