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

How to Set Data Source at Runtime

9 Answers 1055 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Mike
Top achievements
Rank 1
Mike asked on 25 Oct 2008, 10:03 PM
Following the example in Getting Started, we have been able to create a report class, set a data connection, preview it, then drop the class into a form in a web application project and view it.  OK for a simple prototype, but no good in production on client's server since data connection string will be different and sql select string will vary based on user input.

So we need to bind the data source to the report at runtime.

The explanations on p 34 of pdf documentation and FAQ of chm help file capture the idea, but we need some additional detail.

This is a web application project.  The code we are trying to use to bind a data adapter to the report is below. It was copied from the documentation.  It is in the aspx hosting the report viewer which was defined in a separate class project and imported via the references tab.  The report has a data  source defined in that class.

Where does this code go?  It would have to be in the aspx page hosting the report viewer, right? If so, where?   The documentation says 'in the report's constructor'.  If so, could you please provide an example?

namespace OurWebApp
{
  public partial class TelericTest : System.Web.UI.Page
  {
    protected void Page_Load(object sender, EventArgs e)
    {
      String s = "";
      String sSelect = "Select * from jvClaim where Createdt >= '09/01/2008'";
      s = cms.sqlClass.getConnString();
      SqlConnection conn = new SqlConnection(s);
      SqlDataAdapter adapter = new SqlDataAdapter(sSelect, conn);
      DataSet dataSet = new DataSet();
      adapter.Fill(dataSet);

      //this.DataSource = dataSet;  ???
      //this.DataMember = "Table";  ???
    }
  }
}

Many thanks,
Mike Thomas







9 Answers, 1 is accepted

Sort by
0
Steve
Telerik team
answered on 27 Oct 2008, 06:40 PM
Hello Mike,

Please take a look at the following code library: Use the connectionString from your app's config file and let us know if further help is needed.

Greetings,
Steve
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Mike
Top achievements
Rank 1
answered on 27 Oct 2008, 09:59 PM
Many thanks Steve.  I think we are slowly coming to a consensus about the suitability of the report control.

Here is the main question, which was in my first posting in this thread.  In the sample app, they put the "Select..." statement in at design time.  They put it in what I would call the report's constructor, in the class project.  How do we put the select statement in at runtime?  For example, the user indicates via input on a web form that he wants the "Top 100" rows, or the "Top 5".  I don't think we have any reports where the query is 'canned' at design time.

Again, please look at the example I gave in the first posting.  It's from your documentation.  I cites the page. Where does this code go? (You can see in the first posting I tried to use the On_Load event of the aspx page hosting the report - this is crealry wrong, so where would it go?)  Can the constructor for the report be accessed at runtime?  If so how?  Could you give an example, remembering that this is a web application.

Many thanks
Mike Thomas

0
Craig
Top achievements
Rank 2
answered on 28 Oct 2008, 12:21 AM
Hi Mike,

Here is how I would do it:

Use a public property or report parameter to pass in the SQL statuement and then use the NeedDataSource event to populate the report with the code below.

Then you would bind by using report.DataSource = Table

Also, if you use this event, you need to put me.Datasource = Nothing in the Public Sub New after the InitalizeComponent.
0
Mike
Top achievements
Rank 1
answered on 28 Oct 2008, 02:33 AM
Many thanks jalmto - I appreciate the help.  Still, I don't see where all of this is going on.  There is the class project in which the report designed, then there is the project and aspx page which hosts the report.

Where is the NeedDataSource event trapped?  This has to be a common scenario; a user enters parameters into a web page, then the report is called and the data is fed in. That way we can pull only the data we need from SQL Server. At least that's how it works with CrystalReports and the MSFT report viewers.

What I am looking for is a simple 10 step description of how to do this. Surely there has to be an example somewhere?

Here is basically what I expect to do:

-Design the report in a separate class project
- Hook up a data source (on the design computer)  to be able to design and preview the report
- 'Import' the report class into  a web application project as a reference
(so far so good)
- Make a form where the user enters the parameters for the report & clicks the "GO" button
Call the hosting form which contains the report viewer, select the data into a dataset, attach it to the report, then display the report.

I would love to see a full example or a step by step description of how to do this, or whatever its equivalent would be with the Telerik report control.

Thanks
Mike Thomas





charles
Top achievements
Rank 1
commented on 31 Jul 2022, 02:19 PM

I am trying out the product and have the same questions as Mike had years ago.

I have spent hours searching documentation for how to use this and am running out of time that I can spend and will have to move on to auditing siomething else.

To recap

C#  WEB form app

I want to create a report using a data model 

Bind data to the report at run time

 

Todor
Telerik team
commented on 03 Aug 2022, 01:11 PM

Hi Charles,

I suggest trying the ObjectDataSource component. Generally, it invokes custom logic to retrieve the data in run-time.

The other option would be to instantiate the report and change its DataSource with code. If you use the HTML5 ASP.NET Web Forms Report Viewer, you need to create a custom ReportSource Resolver, where to instantiate the report definition and modify it as required. You will have to return an InstanceReportSource with ReportDocument containing the modified Report instance.

0
David Silveria
Top achievements
Rank 1
answered on 29 Oct 2008, 10:19 AM
If you're going to tangle the sql query manually on each request - then you do not need the ReportParameters which are basically there to help work with the already received data and provide built-in UI.
For your purpose I would work with parameters on db level and create my own UI. Nevertheless, here is a video, that might  shed more light - Telerik Reporting - Design Time Support for Parameterized Queries

Cheers



0
Mike
Top achievements
Rank 1
answered on 29 Oct 2008, 02:42 PM
David,

I completely agree - I don't want to pull in a dataset with a million records,  then use report parameters to filter the set down to the 35 the user wants to see.

My question is how to tangle the dataset at run time.

Mike Thomas

-1
Steve
Telerik team
answered on 30 Oct 2008, 10:38 AM
Hello Mike,

We've answered your inquiry in the support thread you have opened on the matter.

Best wishes,
Steve
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
1
Dan
Top achievements
Rank 1
answered on 26 Jan 2011, 09:44 PM
Sadly, answering his question in the support ticket doesnt help all the other people coming to the thread looking for the same answers.
0
Steve
Telerik team
answered on 27 Jan 2011, 09:46 AM
Hello Dan,

This thread is two years old (as probably our forum has warned you) and its contents are no longer current. In Q1 2010 we've introduced Data Source Components that are responsible for connecting to your data. Check the respective help articles in the latter help section and videos in telerik.tv that elaborate on using them.

All the best,
Steve
the Telerik team
Get started with Telerik Reporting with numerous videos and detailed documentation.
Daniel
Top achievements
Rank 1
Iron
commented on 13 Aug 2024, 05:28 PM

Steve, that link provides no code to show how to do this, at least the few threads I followed. It seems getting an example of supplying data to a report at runtime is difficult. Even the documentation on how to create a report at runtime doesn't show how to add data. I know of no report that doesn't need data.
Todor
Telerik team
commented on 16 Aug 2024, 07:03 AM

Hi Daniel,

Please, note that this thread is more than 10 years old and some of the information may be outdated.

Depending on the exact scenario, we provide various approaches for attaching data run time to the reports. Here are two popular approaches you may use:


Tags
General Discussions
Asked by
Mike
Top achievements
Rank 1
Answers by
Steve
Telerik team
Mike
Top achievements
Rank 1
Craig
Top achievements
Rank 2
David Silveria
Top achievements
Rank 1
Dan
Top achievements
Rank 1
Share this question
or