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

Using SQLAdapter parameters with report parameters?

9 Answers 258 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Stefan Willebrand
Top achievements
Rank 1
Stefan Willebrand asked on 10 Feb 2009, 12:31 PM
I am using an SQLAdapter that runs a select statement with a few parameters to the database in order to collect data for my report. Is there a way that I can use report parameters for letting the user change the parameters in the report or do I have to put the controls on the page that holds the report viewer where the user can change the inputs?

All I found was this old video http://www.telerik.com/clientsfiles/product.videos/28/ and I also read that you would have built in support for this in future releases. Any info on this?

9 Answers, 1 is accepted

Sort by
0
Steve
Telerik team
answered on 10 Feb 2009, 04:00 PM
Hello Stefan,

Generally there are two distinct ways of getting the parameters values:
  • Through your own user interface or any other means (e.g. query string).
  • Through the report parameters defined in the ReportParameters collection of the report.

Using one of those does not necessarily involve the usage of the other one and it is up to you to choose the approach that would best suit your case. More info is available in this KB article.
As for the built-in support you mention, note that Telerik Reporting does not provide its own data layer but depends on the existing .NET objects (DataSet, Data Table, DataView, ADO.NET, lists - for more information on report data binding, please, refer to this help topic). Because of that, the Telerik Reporting Data Source Wizard cannot be used to connect to parameterized data source such as stored procedure or a Select command with parameters out of the box.

Sincerely yours,
Steve
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Stefan Willebrand
Top achievements
Rank 1
answered on 10 Feb 2009, 04:20 PM
Ok, is there a way to use several SQL Data Adapters for the same report. For example I would like to display one detail section with data from SQL Data Adapter1 and one detail section with data from SQL Data Adapter2 in the same report?
0
Steve
Telerik team
answered on 10 Feb 2009, 05:13 PM
Hello Stefan,

You can achieve that by using a subreport item.

Kind regards,
Steve
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Stefan Willebrand
Top achievements
Rank 1
answered on 10 Feb 2009, 07:42 PM
Is it then possible for me to access the reports used in the subreport programmatically to change the inputs for the sub reports?

Currently I am using the following code:

ReportViewer1.Report =

New hedgepl

 

 

Dim repparam As hedgepl

 

repparam = ReportViewer1.Report

repparam.EndDate = DateTime.Now()

If I add a master with the name hedgeplmaster I guess it would look something like this:

 

ReportViewer1.Report =

New hedgeplmaster()

 

 

Dim repparam As hedgepl

 

repparam = ReportViewer1.Report     [WHAT SHOULD I CHANGE HERE TO ACCESS THE SUB REPORT?]

repparam.EndDate = DateTime.Now()

0
Stefan Willebrand
Top achievements
Rank 1
answered on 10 Feb 2009, 07:49 PM
I think I solved it with this:

ReportViewer1.Report =

New hedgeplmaster()

 

 

Dim Sub1 As Telerik.Reporting.SubReport

 

Sub1 = ReportViewer1.Report.Items(1).Items(0)

 

Dim repparam As hedgepl

 

repparam = Sub1.ReportSource

repparam.EndDate = DateTime.Now()

Does that look ok to you?

0
Stefan Willebrand
Top achievements
Rank 1
answered on 10 Feb 2009, 10:01 PM
I have this one issue left, on my subreport I now have an SQLDataAdapter, SQLCommand and SQLConnection. For the connection string property in design time for the SQLConnection I cannot see any of the connectionstrings defined in my app.config but only the connections defined in the server explorer of my visual studio.

How can I get this SQLConnection to use one of my defined connectionstrings in my app.config settings?

If needed I could pass this from my application but I do not see how I could access the SQLConnection from my application. I can access the SQLDataAdapter by defining a SQLDataAdapter and pointing it to the right one by: SubReport.ReportSource.DataSource but I do not see how to create an SQLConnection object and then point it ti the SQL Connection that is present in the SubReport.

This is my last issue to get this to work :-)
0
Steve
Telerik team
answered on 11 Feb 2009, 09:33 AM
Hi Stefan,

Generally when you are using the Report Wizard to create the reports, you would go through a step that asks you to save the connectionString you use into your web/app config files. This way you can easily re-use it when creating other reports and changing it would affect the other ones as well. Here is also a code library that shows how to access the connectionStrings in your config files from your report constructor.
Note this is not specific to our product - any valid approach for .NET is applicable for the reports as they are standard .NET classes.

All the best,
Steve
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Stefan Willebrand
Top achievements
Rank 1
answered on 11 Feb 2009, 11:26 PM
Well, I still have problems with this. Just now I wrote the following:

Partial

Public Class trades

Inherits Telerik.Reporting.Report

Public Sub New

InitializeComponent()()

Me.TradesDataSetTableAdapter1.Connection.ConnectionString = ConfigurationManager.ConnectionStrings("SQLCon").ConnectionString

'TODO: This line of code loads data into the 'TradesDataSet.TradesDataSetTable' table. You can move, or remove it, as needed.

Try

Me.TradesDataSetTableAdapter1.Fill(Me.TradesDataSet.TradesDataSetTable)

Catch ex As System.Exception

'An error has occurred while filling the data set. Please check the exception for more information.

System.Diagnostics.Debug.WriteLine(ex.Message)

End Try

End Sub

When I tried to run it with the new line in bold text above I get the error that object reference is not set to an instance of an object.

When I use the code below yesterday on another report it worked fine:

Partial

Public Class hedgepl

Inherits Telerik.Reporting.Report

Public Sub New()

InitializeComponent()

Me.SqlConnection1.ConnectionString = ConfigurationManager.ConnectionStrings("Reports.My.MySettings.stefantest").ConnectionString

End Sub

What is the difference between these two other than the fact that I am using an SqlConnection in the last example?

0
Steve
Telerik team
answered on 13 Feb 2009, 03:45 PM
Hi Stefan,

The difference between those two as described in the code library referenced in my previous post is that in the first case you have used the report wizard to generate typed dataset for you and you access it directly via  TradesDataSetTableAdapter1.Connection.ConnectionString, while the second approach is when you setup the datasource on your own, creating SqlCommand, SqlConnection etc.
In this case you obviously do not have predefined dataset, so you need to set the connectionString to the SqlConnection:
SqlConnection1.ConnectionString = ConfigurationManager.ConnectionStrings("Reports.My.MySettings.stefantest").ConnectionString

"Object reference is not set to an instance of an object" is a generic framework error and you should debug to see what is causing it in order to correct the error.

Sincerely yours,
Steve
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
Tags
General Discussions
Asked by
Stefan Willebrand
Top achievements
Rank 1
Answers by
Steve
Telerik team
Stefan Willebrand
Top achievements
Rank 1
Share this question
or