Accessing Datasource.SelectComand via Report Viewer code

4 posts, 1 answers
  1. Tomica
    Tomica avatar
    147 posts
    Member since:
    Apr 2008

    Posted 16 May 2011 Link to this post

    I have a series of reports that depend on a variety of differing SQL queries. They vary by joins and several other criteria, so simple parameter substitution is not an option. I need to set the SQL Select Command at the time the report is initiated on the ASPX page that contains the Report Viewer.

    In another thread, I have found out how to access certain report variables using the following technique:


    Dim
    report As Telerik.Reporting.Report = DirectCast(Me.ReportViewer1.Report, Telerik.Reporting.Report)

     

     

     

    Dim txt As Telerik.Reporting.TextBox = TryCast(report.Items.Find("titleTextBox", True)(0), Telerik.Reporting.TextBox)
     

     

     

    txt.Value = "

     

    Updated Title Text"

    How would I do the equivalent for the Datasource name, connection string or select command?

    I need a clue as to the syntax and form, as the above "find" for a text control doesn't seem to apply.

     

     

     

     

     

  2. Answer
    Steve
    Admin
    Steve avatar
    10941 posts

    Posted 19 May 2011 Link to this post

    Hi Tom,

    If you're using the SqlDataSource Component to connect the report to data, then you would have to cast to it e.g.:
    Copy Code
    Dim report As New Report5()
    Dim sqlDataSource1 As Telerik.Reporting.SqlDataSource = DirectCast(report.DataSource, Telerik.Reporting.SqlDataSource)
    sqlDataSource1.ConnectionString = "<your_connection>"
    sqlDataSource1.SelectCommand = "<your_select_statement>"
    ReportViewer1.Report = report

    All the best,
    Steve
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  3. DevCraft banner
  4. Kumron
    Kumron avatar
    2 posts
    Member since:
    Sep 2011

    Posted 24 Sep 2011 Link to this post

    I want to Accessing Datasource  via Report Viewer code with to table in report
  5. Steve
    Admin
    Steve avatar
    10941 posts

    Posted 27 Sep 2011 Link to this post

    Hello Kumron,

    The code from previous post is still applicable. You just need to get the report from the report viewer and locate the Table item e.g.

    Dim report As Telerik.Reporting.Report = DirectCast(Me.ReportViewer1.Report, Telerik.Reporting.Report)
    Dim table As Telerik.Reporting.Table = DirectCast(report.Items.Find("crosstab1", True)(0), Telerik.Reporting.Table)
     
    Dim sqlDataSource1 As Telerik.Reporting.SqlDataSource = DirectCast(table.DataSource, Telerik.Reporting.SqlDataSource)
    sqlDataSource1.ConnectionString = "<your_connection>"
    sqlDataSource1.SelectCommand = "<your_select_statement>"


    Kind regards,
    Steve
    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

Back to Top