954,593 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Passing parameters from webform dynamically

Dear all .Netters,
In my report, I have 3 parametes(Par1,Par2,Par3)
In this case, I only want to give parameter only for Par1,Par2.
I set Par3 as interal and hidden parameter.
In my webform, I write these code :

ReportViewer1.ProcessingMode = ProcessingMode.Local

Dim rep As LocalReport = ReportViewer1.LocalReport
rep.ReportPath = "RptProductPhoto.rdlc"

Dim I As Byte
Dim GetParameter As String = ""
Dim TotalParameter As Byte
TotalParameter = rep.GetParameters.Count
Dim par(TotalParameter - 1) As Microsoft.Reporting.WebForms.ReportParameter
For I = 0 To rep.GetParameters.Count - 1
GetParameter = rep.GetParameters.Item(I).Name
Select Case LCase(GetParameter)
Case "par1"
par(I) = New Microsoft.Reporting.WebForms.ReportParameter(GetParameter, "Par1")
Case "par2"
par(I) = New Microsoft.Reporting.WebForms.ReportParameter(GetParameter, "Par2")
End Select
Next
rep.SetParameters(par)
The program yields an error.
"Value cannot be null." reffering to "rep.SetParameters(par)" line code.

So, what should I do to remove the error ?

Thanks,

Kusno

Kusno
Junior Poster
191 posts since Aug 2007
Reputation Points: 11
Solved Threads: 17
 

make sure of the names of your parameters. like par1 is not Par1. you are pulling blank values. try that. otherwise if you are only calling two values from this entire form, just call those two fields directly. uses less coding and no loops. Plus, less room for error!

SheSaidImaPregy
Veteran Poster
1,080 posts since Sep 2007
Reputation Points: 43
Solved Threads: 68
 

Why do I use loop ??
1. This form will be used by more than 1 reports.
2. Each reports will have different parameters.

"par1 is not Par1" is not a problem, because i only set lower case variable GetParameter.

Thanks

Kusno
Junior Poster
191 posts since Aug 2007
Reputation Points: 11
Solved Threads: 17
 

I am confused by your code.. but let's see.

You set par() equal to the total parameters, so if you have 3 parameters, it will be par(3). Are you trying to make this into an array for reading it later? Cause you are never adding the values to the array.

Try using this to add the values to the array:

ReportViewer1.ProcessingMode = ProcessingMode.Local

Dim rep As LocalReport = ReportViewer1.LocalReport
rep.ReportPath = "RptProductPhoto.rdlc"

Dim I As Byte
Dim GetParameter As String = ""
Dim TotalParameter As Byte
TotalParameter = rep.GetParameters.Count
Dim par(TotalParameter - 1) As Microsoft.Reporting.WebForms.ReportParameter
For I = 0 To rep.GetParameters.Count - 1
GetParameter = rep.GetParameters.Item(I).Name
Select Case LCase(GetParameter)
Case "par1"
par(I) = New Microsoft.Reporting.WebForms.ReportParameter(GetParameter, "Par1")
Case "par2"
par(I) = New Microsoft.Reporting.WebForms.ReportParameter(GetParameter, "Par2")
End Select
rep.SetParameters(par(I))
Next

This adds the certain parameter to your array of par. I was confused why you had it after the Next command and just (par) and not with a value.. so it makes sense now. Since you never added anything to "par", it returned null. Try that.

SheSaidImaPregy
Veteran Poster
1,080 posts since Sep 2007
Reputation Points: 43
Solved Threads: 68
 

I've tried your code, but this was happened :

Unable to cast object of type 'Microsoft.Reporting.WebForms.ReportParameter' to type 'System.Collections.Generic.IEnumerable`1[Microsoft.Reporting.WebForms.ReportParameter]'.

I don't know why Reporting Services compels all parameters to be filled in, but in my experience when using Crystal Reports, we can pass to certain parameters that we want to.

But unfortunately, Crystal Reports that bundled in VS 2005 still has bug.

Kusno
Junior Poster
191 posts since Aug 2007
Reputation Points: 11
Solved Threads: 17
 

here, to find out what it is spitting out, try debugging the lines that are "null". If you can, make the string write out the par lines and see what it is displaying. Let me know.

SheSaidImaPregy
Veteran Poster
1,080 posts since Sep 2007
Reputation Points: 43
Solved Threads: 68
 

Two things.. maybe on your first code it requires you to specifiy the visibibility, so replace these lines:
(GetParameter, "Par1", false/true)
(GetParameter, "Par2", false/true)
and make the false/true set to your visibility, false none, true visible.

The other, try this:

ReportViewer1.ProcessingMode = ProcessingMode.Local

Dim rep As LocalReport = ReportViewer1.LocalReport
rep.ReportPath = "RptProductPhoto.rdlc"

Dim I As Byte
Dim GetParameter As String = ""
Dim TotalParameter As Byte
TotalParameter = rep.GetParameters.Count
Dim paramlist As New Generic.List(Of ReportParameter)
For I = 0 To rep.GetParameters.Count - 1
GetParameter = rep.GetParameters.Item(I).Name
Select Case LCase(GetParameter)
Case "par1"
par.Add(New ReportParameter(GetParameter, "Par1"))
Case "par2"
par.Add(New ReportParameter(GetParameter, "Par2"))
End Select
Next
rep.SetParameters(par)
SheSaidImaPregy
Veteran Poster
1,080 posts since Sep 2007
Reputation Points: 43
Solved Threads: 68
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You