Binding a Report to a Programmatically Created DataSet

3 posts, 1 answers
  1. Glenn Boothe
    Glenn Boothe avatar
    21 posts
    Member since:
    Jul 2008

    Posted 16 Sep 2009 Link to this post


    I am building an application that uses Telerik Reports and I need to figure out a way to be able to create a report independent of any database and then at runtime bind it to a DataSet created completely in code.  To make matters worse, I am unable to add the reporting project to a solution that contains the project I need the report for because that project is a Web Site and there doesn't appear to be any way of getting that done.  What I am able to do is to build the Report Project and then upload the binaries from the Report Project to the website.  From there I can view the Report on the page using the ReportViewer.

    Since I am not using a database, I am unable to use the Telerik Reporting Wizard to automatically create my dataset and databind the fields to the data.  What I have done is added a DataSet to my Report Project and built it by hand using the designer to have the exact schema of my results DataSet that I am creating at runtime.

    Here is essentially what I'm doing right now
    1) Pull records I need in the report from the database into my code
    2) Perform relatively complex business logic on the rows that is either impossible or unwise to do in SQL
    3) While processing the rows, manually add the results to a DataTable which I then add to a DataSet
    4) After processing, create a new instance of my report set myReport.DataSource = myDataSet
    5) Add the report to the viewer

    When I bring up the page that holds the viewer, the desired report appears in the viewer, but does not contain any data.  Obviously there is a gap in my understanding of how Telerik Reporting works.  Is it possible to bind data to a report without it necessarily being pulled from a database?

  2. Answer
    Chris Gillies
    Chris Gillies avatar
    384 posts
    Member since:
    May 2006

    Posted 17 Sep 2009 Link to this post

    I'm not too good in following thoughts in explicitly long explanations, but I notice some contradictions:

    "Since I am not using a database" vs. "Pull records I need in the report from the database", so the question is are you creating all the data by hand or you have a database to pull it from. Actually how you prepare and bind your data is not relevant, as long as it is one of the supported ( and dataset is.
    So next question would be, where do you place the binding code i.e. myReport.DataSource = myDataSet. The three possible options are:
    • report constructor (when the data would not change and initial data is known)
    • NeedDataSource event of the report ( which sounds like what you're after i.e. you can do the preparation of data based on some params/user input. Note that in this case myReport should be of type Telerik.Reporting.Processing.Report i.e. use the sender.
    • in the application e.g. Page_Load event of the report.

    Now that this is cleared, check when the report ends up empty. Does it happen on preview or in runtime, or maybe it works on your dev machine but is empty on your server? If the latter, these articles would explain what to do:

    If still no dice, ask yourself if the data is coming through, and if this is problem with the report - use DataGrid or other databound control to see if it binds correctly.
    PRABHU avatar
    3 posts
    Member since:
    Jul 2010

    Posted 13 Jul 2010 Link to this post




    public class PDF_Export : Report





    public PDF_Export()




    this .DocumentName = "Patient" ;



    this .DataSource = GetTable();



    this .DataMember = "Table" ;







    private DataTable GetTable()





    DataTable table = new DataTable ();




    "Dosage" , typeof ( int ));




    "Drug" , typeof ( string ));




    "Patient" , typeof ( string ));




    "Indocin" , "David" );




    "Enebrel" , "Sam" );


    return table;




    then in my aspx page,i have the followong code for my button click


    protected void Button1_Click( object sender, EventArgs e)










    PDF_Export myRep = new PDF_Export ();




    ReportProcessor reportProcessor = new ReportProcessor ();


    RenderingResult result = reportProcessor.RenderReport( "PDF" , myRep, null );



    string fileName = result.DocumentName + ".pdf" ;



    Response.ContentType = result.MimeType;



    Response.Buffer =

    true ;




    "Content-Disposition" , string .Format( "{0};FileName=\"{1}\"" , "attachment" , fileName));









    catch ( Exception ex)






    My Problem is It generates  pdf BUT WITH NO DATA IN THE PDF.

    Can you please help?
Back to Top