Solved

Error trying to generate a report with parameters

Posted on 2011-02-22
12
477 Views
Last Modified: 2012-05-11
I have created a report that contains parameters.  I set it up so that the parameters would be hidden.  I am trying to run this report and have it displayed in a report viewer on an asp page that I have.  I basically created a page that will accept the parameters and then click a button to generate the report based on the parameters the user enters.  Some of the parameters will be null at times.
I am running the program and I get a message.  Can anyone please tell me what my problem is?
The message is: Object reference not set to an instance of an object.

Here's the code too:
 Protected Sub btnSubmit_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSubmit.Click
        setParams()
        ReportViewer1.ProcessingMode = Microsoft.Reporting.WebForms.ProcessingMode.Remote
        ReportViewer1.ServerReport.ReportServerUrl = New System.Uri("http://srmha-96648582/ReportServer")
        ReportViewer1.ServerReport.ReportPath = "/Report Project6/CCD"
(The message occurs on this next line)  
        RptParameters(0) = New Microsoft.Reporting.WebForms.ReportParameter("user", txtUserName1.Text)
        RptParameters(1) = New Microsoft.Reporting.WebForms.ReportParameter("keyword", txtKeyWord.Text)
        RptParameters(2) = New Microsoft.Reporting.WebForms.ReportParameter("userlastname", userLastName)
        RptParameters(3) = New Microsoft.Reporting.WebForms.ReportParameter("userfirstname", userFirstName)
        RptParameters(4) = New Microsoft.Reporting.WebForms.ReportParameter("custlastname", custLastName)
        RptParameters(5) = New Microsoft.Reporting.WebForms.ReportParameter("custfirstname", custFirstName)
        RptParameters(6) = New Microsoft.Reporting.WebForms.ReportParameter("startdate", txtStartDate.Text)
        RptParameters(7) = New Microsoft.Reporting.WebForms.ReportParameter("enddate", txtEndDate.Text)
        ReportViewer1.ServerReport.SetParameters(RptParameters)
        ReportViewer1.ServerReport.Refresh()

    End Sub
0
Comment
Question by:mmtcunningham1
  • 7
  • 5
12 Comments
 
LVL 51

Expert Comment

by:HainKurt
ID: 34953950
code for setParams() ???
0
 

Author Comment

by:mmtcunningham1
ID: 34954013
Sub setParams()
        Dim i As Integer
        If ddlUserName.SelectedValue <> "" Then
            i = ddlUserName.SelectedValue.IndexOf(",")
            userLastName = ddlUserName.SelectedValue.Substring(0, i)
            userFirstName = ddlUserName.SelectedValue.Substring(i + 1, ddlUserName.SelectedValue.Length - (userLastName.Length + 1))
        Else
            userLastName = ""
            userFirstName = ""
        End If
        If ddlCustomerName.SelectedValue <> "" Then
            i = ddlCustomerName.SelectedValue.IndexOf(",")
            custLastName = ddlCustomerName.SelectedValue.Substring(0, i)
            custFirstName = ddlCustomerName.SelectedValue.Substring(i + 1, ddlCustomerName.SelectedValue.Length - (custLastName.Length + 1))
        Else
            custLastName = ""
            custFirstName = ""
        End If
    End Sub
0
 
LVL 51

Expert Comment

by:HainKurt
ID: 34954036
above code is not related :)

how do you define RptParameters?
0
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 
LVL 51

Expert Comment

by:HainKurt
ID: 34954043
try:

RptParameters(0) = New Microsoft.Reporting.WebForms.ReportParameter("user", txtUserName1.Text)
-->
RptParameters.add(New Microsoft.Reporting.WebForms.ReportParameter("user", txtUserName1.Text))

same for all others
0
 

Author Comment

by:mmtcunningham1
ID: 34954180
I have it defined like this:
 Dim RptParameters() As Microsoft.Reporting.WebForms.ReportParameter
0
 

Author Comment

by:mmtcunningham1
ID: 34954318
RptParameters.add(-----)) is not allowed for system.array is the message i'm getting
0
 
LVL 51

Expert Comment

by:HainKurt
ID: 34954358
something like this:

Dim RptParameters() As Microsoft.Reporting.WebForms.ReportParameter = new Microsoft.Reporting.WebForms.ReportParameter(7)
0
 
LVL 51

Accepted Solution

by:
HainKurt earned 500 total points
ID: 34954370
or

Dim RptParameters(7) As Microsoft.Reporting.WebForms.ReportParameter

dont remember the exacts syntax :)
0
 

Author Comment

by:mmtcunningham1
ID: 34954402
that won't work
0
 
LVL 51

Expert Comment

by:HainKurt
ID: 34954529
this did not work?

Dim RptParameters(7) As Microsoft.Reporting.WebForms.ReportParameter
RptParameters(0) = New Microsoft.Reporting.WebForms.ReportParameter("user", txtUserName1.Text)
...
RptParameters(7) = New Microsoft.Reporting.WebForms.ReportParameter("enddate", txtEndDate.Text)
ReportViewer1.ServerReport.SetParameters(RptParameters)
...
0
 

Author Comment

by:mmtcunningham1
ID: 34954551
This worked for me.
Dim RptParameters(7) As Microsoft.Reporting.WebForms.ReportParameter
0
 
LVL 51

Expert Comment

by:HainKurt
ID: 34954584
or use this syntax (from MS - Generic List approach)

Dim paramList As New Generic.List(Of ReportParameter)
   paramList.Add(New ReportParameter("EmpID", "288", False))
   paramList.Add(New ReportParameter("ReportMonth", "12", False))
   paramList.Add(New ReportParameter("ReportYear", "2003", False))
ReportViewer1.ServerReport.SetParameters(paramList)

http://msdn.microsoft.com/en-us/library/ms252663(v=vs.80).aspx

in your case:

Dim RptParameters As New Generic.List(Of Microsoft.Reporting.WebForms.ReportParameter)
RptParameters.Add(New Microsoft.Reporting.WebForms.ReportParameter("user", txtUserName1.Text))
...
RptParameters.Add(New Microsoft.Reporting.WebForms.ReportParameter("enddate", txtEndDate.Text))
ReportViewer1.ServerReport.SetParameters(RptParameters)

Open in new window

0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
Hi, I have heard from my friends that it’s not possible to create Label Printing report using SSRS. I am amazed after hearing this words not possible in SSRS. I googled lot and found that it is possible to some of people know about the Report Bui…
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

808 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question