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

Accessing Datasource.SelectComand via Report Viewer code

3 Answers 155 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Tomica
Top achievements
Rank 2
Tomica asked on 17 May 2011, 01:34 AM
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.

 

 

 

 

 

3 Answers, 1 is accepted

Sort by
0
Accepted
Steve
Telerik team
answered on 19 May 2011, 04:51 PM
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
0
Kumron
Top achievements
Rank 1
answered on 24 Sep 2011, 07:15 AM
I want to Accessing Datasource  via Report Viewer code with to table in report
0
Steve
Telerik team
answered on 27 Sep 2011, 10:13 AM
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 >>

Tags
General Discussions
Asked by
Tomica
Top achievements
Rank 2
Answers by
Steve
Telerik team
Kumron
Top achievements
Rank 1
Share this question
or