Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Error trying to generate a report with parameters

Posted on 2011-02-22
12
Medium Priority
?
487 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 61

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 61

Expert Comment

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

how do you define RptParameters?
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 61

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 61

Expert Comment

by:HainKurt
ID: 34954358
something like this:

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

Accepted Solution

by:
HainKurt earned 2000 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 61

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 61

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

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

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

Written by Valentino Vranken. Introduction: The first step of creating a SQL Server Reporting Services (SSRS) report involves setting up a connection to the data source and programming a dataset to retrieve data from that data source.  The data…
Hi All, I am here to write a simple article to move SSRS (SQL Server Reporting Services) reports from one server to another. When I have faced the same issue to move reports those were developed by developer on development server and now need to …
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
Suggested Courses

886 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