This has to be the simpliest of all report questions and I fill dumb for asking but I can't find any help on telerik website. I have spent hours looking.
Thanks!
10 Answers, 1 is accepted
report.ReportParameters.Add("myID", ReportParameterType.Integer, 123); or report.ReportParameters["myID"].Value = 123; //if parameter was created by designer |
and in your report:
int id = (int)r.ReportParameters["myID"].Value; |
Hope this helps.
Thank you for replying. Thats sounds like it might work. Problem for me is that code doesn't make since so I don't know how to implement it.
When I paste your code into my win form, I get an error. I'm sure its I'm not exposing something or initiating something correctly to make it work. I feel so stupid. Then the part that goes into the report, I have no idea where to insert that.
InvoiceReport inv = new InvoiceReport() //classname of your report
inv.ReportParameters.Add("InvNr", ReportParameterType.Integer, 123);
//to display your report
repView1.Report = inv;
repView1.RefreshReport();
//in your reports contstructor set
Datasource = null;
//then in NeedDataSourceEvent (is fired if datasource is null)
//get your parameter
int invNr = (int)ReportParameters["InvNr"].Value;
//if you have specified some sqlDataSource
sqlDataSource1.SelectCommand = "SELECT * FROM Invoice WHERE InvNr='" + invNr + "'";
DataSource = sqlDataSource1;
//and bind some controls to this datasource, see documentation for this
___________________________________________________________________________
Dim myNum As String = "808080"
Dim myreport As New TagLabel
myreport.ReportParameters.Add("ParamTagNum", ReportParameterType.Integer, myNum)
ReportViewer1.Report = myreport
ReportViewer1.RefreshReport()
___________________________________________________________________________
Here is the code that is in my Report NeedDataSourceEvent currently:
___________________________________________________________________________
Dim sql As String = ""
sql = "SELECT * FROM myTable " & _
"WHERE TagNum = @TAGNUM"
Dim connectionString As SqlConnection
connectionString = New SqlConnection("xxxxxxx")
adapter.SelectCommand = New SqlCommand(sql, connectionString)
adapter.SelectCommand.Parameters.Add(New SqlParameter("@TAGNUM", "199"))
Dim dataSet As New DataSet()
adapter.Fill(dataSet)
Me.DataSource = dataSet
___________________________________________________________________________
I have no idea how to take your code and put into the NeedDataSourceEvent.
Your code:
int invNr = (int)ReportParameters["InvNr"].Value
That errors out. invNr says its not declared. Which I know but don't know what it is that I am declairing. Is it a string? Some other type of object? (int) doesn't accept that number of arguments.
Sorry for bugs in my code ... I wrote it in notepad ...
I am still lost as to how to modify my existing code in the report to accept this incoming parameter from my form.
string key = ReportParameters["key"].Value.ToString();
in NeedDataSource event works fine.
But you have to have some field (textbox...) bound to the datasource. If not, the event is not fired.
It works. Thank you so much for your continued effort to help me. I knew in the end it would be so simple.
To summarize for anyone who might read this in the future:
In Win Form add this code:
Dim myreport As New {NameOfYourReport}
myreport.ReportParameters.Add("{NameOfYourParam}", ReportParameterType.string, "12345")
ReportViewer1.Report = myreport
ReportViewer1.RefreshReport()
In Report Class add this code to NeedDataSourceEvent"
Dim mykey As String
mykey = ReportParameters("{NameOfYourParam}").Value.ToString
Then just use the variable mykey to help build your SQL Select statement.
Why I couldn't find this code anywhere on Telerik website is crazy.
I still can't find the documentation to send the parameters proper way from the winforms reportviewer to the report.
The way it is showed here is no longer valid.
These posts are from 2010, where in Q2 2012 there is a change in the way reports are passed to viewers and ReportProcessor instances - How to migrate your project to utilize the new ReportSource objects.
The blog post elaborates on the report sources settings and includes links to online help articles.
In Visual Studio you can configure viewers' ReportSource properties through the available wizards - Load Report Dialog.
Regards,
Stef
Telerik