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

Winforms, Stored Procedure and a Parameter

2 Answers 194 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Dave
Top achievements
Rank 2
Iron
Iron
Veteran
Dave asked on 08 Dec 2020, 09:46 PM

I've been through the docs at least twice and obviously I'm missing quite a bit.

 

Created two simple, identical, reports with the wizard. One with the report designer, Report1, the other in VS2019, Report2.  They are calling a stored procedure in SQL Server 2016, with a parameter.  Both preview in the designers just fine. Both reports have a parameter set...@batchid Int32 6000

Stored procedure:    select * from batches where batchid=@batchid

I've added the NeedDataSource event to the reports

Telerik.Reporting.UriReportSource uriReportSource = new Telerik.Reporting.UriReportSource();
uriReportSource.Parameters.Add(new Telerik.Reporting.Parameter("@batchid", 7929));
uriReportSource.Uri = @"nunya\Report1.trdp";
reportViewer1.reportSource = uriReportSource;

reportViewer1.RefreshReport();

 

The trdp complains it can't find a connection string. IDK why. There is one in the app.config file which the rest of the application happily uses. When the connection string is embedded, it still does NOT use the Uri parameter.

 

 

Telerik.Reporting.TypeReportSource typeReportSource = new Telerik.Reporting.TypeReportSource();
typeReportSource.Parameters.Add( new Telerik.Reporting.Parameter("@batchid", 7929));
typeReportSource.TypeName = typeof(Report2).AssemblyQualifiedName;
reportViewer.reportSource=typeReportSource;

reportViewer1.RefreshReport();

 

 

 

Here, an exception is thrown in the Report1_NeedDataSource event:.report.Parameters is empty.

Do you have a sample winforms app which uses either the northwind or adventure works databases?

 

TIA

2 Answers, 1 is accepted

Sort by
0
Dimitar
Telerik team
answered on 11 Dec 2020, 03:16 PM

Hi David,

The report engine not being able to find the SQL string despite it being in the configuration file. Usually, it takes its value from the report definition, i.e. from the TRDP file. If this value cannot be resolved to a valid connection string by the Reporting engine, the latter assumes that it is a named/shared connection string and looks for it in the application configuration file. Can you give a little more information on the error that you are getting? It would be nice if you could send us a trace log created by a Trace Listener.

As for the NeedDataSource event that you mentioned, generally, we do not recommend using Report Events since they are a legacy approach for modifying styles, providing data, and logging information about the processing report. Please have a look at the Changes on items in report events are not applied KB that provides better options than events. If you insist on using the NeedDataSource event, you might find it useful to check out the Using NeedDataSource event to connect to data article.

In the meantime, you can check out our WinformsDemos at C:\Program Files (x86)\Progress\Telerik Reporting R3 2020\Examples\CSharp

If the above information does not help solve the issue, please consider also sending us a runnable project with some sample data so that we can inspect it locally.

Looking forward to receiving an update from you.

Regards, Dimitar Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

0
Dave
Top achievements
Rank 2
Iron
Iron
Veteran
answered on 12 Dec 2020, 10:15 PM

Hi Dimitar,

Thanks for the hints and the link.  As advised, discarded the legacy NeedDataSource Report Events.

My mistake was under the impression the report received the parameter directly from the TypeReportSource. It does not.  It comes from Telerik.Reporting.Report.ReportParameter. Once added, it all worked.

 

Tags
General Discussions
Asked by
Dave
Top achievements
Rank 2
Iron
Iron
Veteran
Answers by
Dimitar
Telerik team
Dave
Top achievements
Rank 2
Iron
Iron
Veteran
Share this question
or