Send parameters to telerik report

0 Answers 661 Views
.NET Framework Report Viewer - WinForms
agustin
Top achievements
Rank 1
Iron
Iron
agustin asked on 23 Dec 2021, 03:37 PM | edited on 24 Dec 2021, 03:07 PM
Hello!

I did the sending of data to the parameter of the SQL procedure worse than telerik reporting, it always returns the results that I initially put when I added the parameters to the report. I need to be able to replace those values ​​that I set by default with the ones that I send to obtain different results.

From already thank you very much, greetings

 

Dim telReportStockMinimo As New Telerik.Reporting.Report
        Dim instanceReportSource = New Telerik.Reporting.InstanceReportSource()
        Dim codProddesde = frmSeleccionStockMinimo.lblProdDesde.Text
        Dim codProdhasta = frmSeleccionStockMinimo.lblProdHasta.Text
        Dim cantidad = frmSeleccionStockMinimo.txtcantidadMinima.Text
        instanceReportSource.ReportDocument = New telReportStockMinimo
        Me.ReportViewer1.ReportSource = instanceReportSource
        instanceReportSource.Parameters.Add(New Telerik.Reporting.Parameter("codProdDesde", codProddesde))
        instanceReportSource.Parameters.Add(New Telerik.Reporting.Parameter("codProdhasta", codProdhasta))
        instanceReportSource.Parameters.Add(New Telerik.Reporting.Parameter("cantidad", cantidad))
        ReportViewer1.RefreshReport()
agustin
Top achievements
Rank 1
Iron
Iron
commented on 24 Dec 2021, 12:17 PM

Someone help me with this please, I estimate it should not vary much
Dimitar
Telerik team
commented on 27 Dec 2021, 12:53 PM

Please test updating the instanceReportSource's Parameters before setting it as a ReportSource for the ReportViewer1 object:

Dim telReportStockMinimo As New Telerik.Reporting.Report
        Dim instanceReportSource = New Telerik.Reporting.InstanceReportSource()
        Dim codProddesde = frmSeleccionStockMinimo.lblProdDesde.Text
        Dim codProdhasta = frmSeleccionStockMinimo.lblProdHasta.Text
        Dim cantidad = frmSeleccionStockMinimo.txtcantidadMinima.Text
        instanceReportSource.ReportDocument = New telReportStockMinimo
        instanceReportSource.Parameters.Add(New Telerik.Reporting.Parameter("codProdDesde", codProddesde))
        instanceReportSource.Parameters.Add(New Telerik.Reporting.Parameter("codProdhasta", codProdhasta))
        instanceReportSource.Parameters.Add(New Telerik.Reporting.Parameter("cantidad", cantidad))
        Me.ReportViewer1.ReportSource = instanceReportSource
        ReportViewer1.RefreshReport()

agustin
Top achievements
Rank 1
Iron
Iron
commented on 27 Dec 2021, 02:59 PM


Hello, thanks for answering, I still have the same problem, I leave the report with the parameters that I manually assign to the report in the design
Dimitar
Telerik team
commented on 27 Dec 2021, 03:45 PM

My apologies Agustin, I had misunderstood the problem. You may provide new parameter values to viewer through the ReportViewer.ReportSource.Parameters collection, for example:

Me.ReportViewer1.ReportSource = instanceReportSource
Me.ReportViewer1.ReportSource.Parameters.Add("cantidad", cantidad)

agustin
Top achievements
Rank 1
Iron
Iron
commented on 27 Dec 2021, 07:51 PM

I put it exactly as you told me and it continues to throw me the same as before the report. I am doing a step by step, and the variable gets what I request well, there must be a problem in sending that parameter to the report
agustin
Top achievements
Rank 1
Iron
Iron
commented on 28 Dec 2021, 03:52 PM | edited

any suggestions to fix this? I am using SqlDataSource connection, from it I get a procedure and its parameters ...
agustin
Top achievements
Rank 1
Iron
Iron
commented on 29 Dec 2021, 12:41 PM

Please help me with this, I need to do the reports, I want to pass everything to telerik, lastly give me an example of a project in vb.net
Dimitar
Telerik team
commented on 29 Dec 2021, 03:42 PM

If you use the report parameters with a SqlDataSource, I recommend having a look at the Using Parameters with the SqlDataSource component article. Make sure that you are correctly using the parameters with the query and that you use the report parameters' values at runtime instead of the constant values - Using Report Parameters programmatically.

Check if you can pass parameters through our VB.WinForms demo project. This project can be found in the installation directory of Telerik Reporting > Examples > VB. Test the following code with the MainForm_Load event:

        Dim typeReportSource As New Telerik.Reporting.TypeReportSource()
        typeReportSource.TypeName = GetType(Invoice).AssemblyQualifiedName
        Me.reportViewer1.ReportSource = typeReportSource
        Me.reportViewer1.ReportSource.Parameters.Add("OrderNumber", "SO51089")
        Me.reportViewer1.RefreshReport()

This should load the Invoice report with the report parameter value of SO51089(you should be able to see it when viewing the report.)

If you are passing the report parameters as I have showcased here and in my last reply, the report parameter values should be getting updated and if that is not reflected in the returned data, there is probably something wrong with the SqlDataSource parameters. For that reason, I would like to request you to attach the report definition files, or the whole project, to this thread and I will have a look at them.

You may also record a trace listener while running the WinForms application(your WinForms app) to see if there are any runtime errors - How to: Create and Initialize Trace Listeners.

For an example of a correct setup of using report parameters to set values of SqlDataSource parameters, please have a look at our Dashboard report. It is inside the VB.ReportLibrary project.

agustin
Top achievements
Rank 1
Iron
Iron
commented on 30 Dec 2021, 01:03 AM

good. What I did was read the documentation correctly, however, it does not help me because they only mention how to assign values ​​to parameters that are within the same query in vb. I, on the contrary, already have the sql procedure (which would be the query), which I call with the data source, and this in turn automatically brings me the parameters that I need to use.
agustin
Top achievements
Rank 1
Iron
Iron
commented on 30 Dec 2021, 12:42 PM

here I leave a step by step of what I was doing in images.
First I assign the procedure I want to use

secondly, the parameters I need are automatically assigned to me

third, I assign the parameters in the report

fourth, I open a form and put a reportviewer on it

finally, in the load of this form I apply the code

Dimitar
Telerik team
commented on 30 Dec 2021, 03:29 PM

Thank you for the provided screenshots!

If you have done things exactly as you have shown in the images, then I think that the problem is in image 2, the Configure data source parameters step. In this step, in the Value Combobox, you must select the appropriate report parameter for each SQL query parameter. To demonstrate how the SQL parameters should be set up, I have recorded a short video of this process and have attached it to my comment. While in the video I use the Standalone Designer, the same steps can also be done in the VS designer and they will look exactly the same.

Check out the video and let me know if you need further assistance.

agustin
Top achievements
Rank 1
Iron
Iron
commented on 30 Dec 2021, 04:20 PM

Yes, now it works perfect, it was this that you indicated to me and also a badly ordered line that I had in the parameterization part. I really appreciate your help, excuse me for insisting so much, a hug!
Dimitar
Telerik team
commented on 31 Dec 2021, 08:09 AM

No problem Agustin, glad to hear that the issue is now resolved!

No answers yet. Maybe you can help?

Tags
.NET Framework Report Viewer - WinForms
Asked by
agustin
Top achievements
Rank 1
Iron
Iron
Share this question
or