User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the ASP.NET section within the Web Development category of DaniWeb, a massive community of 456,554 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,485 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our ASP.NET advertiser: Lunarpages ASP Web Hosting
Views: 2860 | Replies: 6
Reply
Join Date: Aug 2007
Location: Somewhere between heaven and hell
Posts: 112
Reputation: Kusno is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 8
Kusno's Avatar
Kusno Kusno is offline Offline
Junior Poster

Passing parameters from webform dynamically

  #1  
Oct 19th, 2007
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
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Sep 2007
Posts: 1,058
Reputation: SheSaidImaPregy is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 61
SheSaidImaPregy SheSaidImaPregy is offline Offline
Veteran Poster

Re: Passing parameters from webform dynamically

  #2  
Oct 20th, 2007
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!
Reply With Quote  
Join Date: Aug 2007
Location: Somewhere between heaven and hell
Posts: 112
Reputation: Kusno is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 8
Kusno's Avatar
Kusno Kusno is offline Offline
Junior Poster

Re: Passing parameters from webform dynamically

  #3  
Oct 22nd, 2007
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
Reply With Quote  
Join Date: Sep 2007
Posts: 1,058
Reputation: SheSaidImaPregy is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 61
SheSaidImaPregy SheSaidImaPregy is offline Offline
Veteran Poster

Re: Passing parameters from webform dynamically

  #4  
Oct 22nd, 2007
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.
Reply With Quote  
Join Date: Aug 2007
Location: Somewhere between heaven and hell
Posts: 112
Reputation: Kusno is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 8
Kusno's Avatar
Kusno Kusno is offline Offline
Junior Poster

Re: Passing parameters from webform dynamically

  #5  
Oct 25th, 2007
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.
Reply With Quote  
Join Date: Sep 2007
Posts: 1,058
Reputation: SheSaidImaPregy is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 61
SheSaidImaPregy SheSaidImaPregy is offline Offline
Veteran Poster

Re: Passing parameters from webform dynamically

  #6  
Oct 25th, 2007
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.
Reply With Quote  
Join Date: Sep 2007
Posts: 1,058
Reputation: SheSaidImaPregy is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 61
SheSaidImaPregy SheSaidImaPregy is offline Offline
Veteran Poster

Re: Passing parameters from webform dynamically

  #7  
Oct 25th, 2007
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)
Last edited by SheSaidImaPregy : Oct 25th, 2007 at 10:44 am.
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb ASP.NET Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the ASP.NET Forum

All times are GMT -4. The time now is 5:24 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC