How to Set Data Source at Runtime

10 posts, 0 answers
  1. Mike
    Mike avatar
    20 posts
    Member since:
    Oct 2008

    Posted 25 Oct 2008 Link to this post

    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







  2. Steve
    Admin
    Steve avatar
    10941 posts

    Posted 27 Oct 2008 Link to this post

    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.
  3. DevCraft banner
  4. Mike
    Mike avatar
    20 posts
    Member since:
    Oct 2008

    Posted 27 Oct 2008 Link to this post

    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

  5. Jeff P
    Jeff P avatar
    37 posts
    Member since:
    Mar 2007

    Posted 27 Oct 2008 Link to this post

    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.
  6. Mike
    Mike avatar
    20 posts
    Member since:
    Oct 2008

    Posted 27 Oct 2008 Link to this post

    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





  7. David Silveria
    David Silveria avatar
    234 posts
    Member since:
    May 2006

    Posted 29 Oct 2008 Link to this post

    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



  8. Mike
    Mike avatar
    20 posts
    Member since:
    Oct 2008

    Posted 29 Oct 2008 Link to this post

    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

  9. Steve
    Admin
    Steve avatar
    10941 posts

    Posted 30 Oct 2008 Link to this post

    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.
  10. Dan
    Dan avatar
    4 posts
    Member since:
    Jan 2011

    Posted 26 Jan 2011 Link to this post

    Sadly, answering his question in the support ticket doesnt help all the other people coming to the thread looking for the same answers.
  11. Steve
    Admin
    Steve avatar
    10941 posts

    Posted 27 Jan 2011 Link to this post

    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.
Back to Top
DevCraft banner