Solved

Error trying to generate a report with parameters

Posted on 2011-02-22
12
480 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:Huseyin KAHRAMAN
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:Huseyin KAHRAMAN
ID: 34954036
above code is not related :)

how do you define RptParameters?
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 51

Expert Comment

by:Huseyin KAHRAMAN
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:Huseyin KAHRAMAN
ID: 34954358
something like this:

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

Accepted Solution

by:
Huseyin KAHRAMAN 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:Huseyin KAHRAMAN
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:Huseyin KAHRAMAN
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

Suggested Solutions

Title # Comments Views Activity
SSRS 2016 Rendering HTML tables 3 55
custom authorization on controller action and HTML in asp.net mvc 1 42
Google Maps with Webforms 1 29
ASP.net Markup for Sub Menu 2 39
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…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

685 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