This is a migrated thread and some comments may be shown as answers.

Binding a Report to a Programmatically Created DataSet

2 Answers 601 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Glenn Boothe
Top achievements
Rank 1
Glenn Boothe asked on 16 Sep 2009, 09:03 PM
Hello,

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?

Thanks

2 Answers, 1 is accepted

Sort by
0
Accepted
Chris Gillies
Top achievements
Rank 1
answered on 17 Sep 2009, 09:22 AM
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 (http://www.telerik.com/help/reporting/designing-reports-connecting-data-to-report.html) 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 (http://www.telerik.com/help/reporting/designing-reports-adding-data-source-needdatasource.html) 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:
  • http://www.telerik.com/support/kb/reporting/general/deploying-telerik-reporting.aspx
  • http://www.telerik.com/support/kb/reporting/designing-reports/using-connectionstrings-from-configuration-file.aspx

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.
0
PRABHU
Top achievements
Rank 1
answered on 13 Jul 2010, 12:30 PM
I AM TRYING TO EXPORT A REPORT TO PDF.

THIS IS MY REPORT.

 

public class PDF_Export : Report

 

 

{

 

public PDF_Export()

 

{

 

this .DocumentName = "Patient" ;

 

 

this .DataSource = GetTable();

 

 

this .DataMember = "Table" ;

 

 

 

}

 

 

private DataTable GetTable()

 

{

 

 

DataTable table = new DataTable ();

 

table.Columns.Add(

 

"Dosage" , typeof ( int ));

 

table.Columns.Add(

 

"Drug" , typeof ( string ));

 

table.Columns.Add(

 

"Patient" , typeof ( string ));

   

 

table.Rows.Add(25,

"Indocin" , "David" );

 

table.Rows.Add(50,

 

"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)

 

{

 

 

try

 

 

{

 

PDF_Export myRep = new PDF_Export ();

 

Telerik.Reporting.Processing.

 

ReportProcessor reportProcessor = new ReportProcessor ();

   

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

  

 

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

   

Response.Clear();

Response.ContentType = result.MimeType;

 

 

Response.Buffer =

true ;

 

Response.AddHeader(

 

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

 

Response.BinaryWrite(result.DocumentBytes);

Response.End();

Response.Close();

 

}

 

 

catch ( Exception ex)

 

{

}

}

 

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

Can you please help?
Tags
General Discussions
Asked by
Glenn Boothe
Top achievements
Rank 1
Answers by
Chris Gillies
Top achievements
Rank 1
PRABHU
Top achievements
Rank 1
Share this question
or