Solved

Error trying to generate a report with parameters

Posted on 2011-02-22
12
476 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
 
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
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: 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

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.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Jquey and footrable 2 35
Class object 2 26
Run time Error 4 34
IIS authorization for web service or reading header data on a webservice post 1 29
How to use Variables  and Custom code in SSRS report and Assembly reference to use compile shared code in SSRS. Its big question for all who are working with SSRS. It is easy to create assembly and refer in SSRS report, still there are some steps…
It is helpful to note: This is a cosmetic update and is not required, but should help your reports look better for your boss.  This issue has manifested itself in SSRS version 3.0 is where I have seen this behavior in.  And this behavior is only see…
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
Edureka is one of the fastest growing and most effective online learning sites.  We are here to help you succeed.

911 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now