Solved

Error trying to generate a report with parameters

Posted on 2011-02-22
12
475 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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

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…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

757 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