Kenny
Kenny

Reputation: 1054

I am getting the following error:Value cannot be null. Parameter name: reportParameters.Any ideas how to fix it?

I created a report using VSS reportviewer. This report has one parameter - a username.

The idea is that when a user clicks the Print icon to print a report, only records belonging to him/her will be displayed for printing, based on his/her logged in username.

I tested the .rdlc with hardcoded values and it works fine.

I am trying to integrate this report with my .net app and I am running into the following error:

Value cannot be null. Parameter name: reportParameters

This error is on this line:

ReportViewer1.LocalReport.SetParameters(params)

Relevant data is below.

    Protected Sub btnUser_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnUser.Click
        which.Value = "U"
        Call Run_Report("")
    End Sub

Sub Run_Report(ByVal sel As String)
    ReportViewer1.Reset()
    ReportViewer1.LocalReport.DataSources.Clear()
    Dim params(0) As ReportParameter

    Select Case which.Value
        Case "U"
            ReportViewer1.LocalReport.DataSources.Add(New ReportDataSource("MyReporttSet", ObjectDataSource1.ID))
            ReportViewer1.LocalReport.ReportPath = "MyReport.rdlc"
            ReportViewer1.LocalReport.Refresh()
            ReportViewer1.LocalReport.SetParameters(params)
    End Select
End Sub

Any ideas on how to fix this?

Thanks alot in advance.

Upvotes: 0

Views: 4534

Answers (2)

senthilkumar2185
senthilkumar2185

Reputation: 2568

If Not String.IsNullOrEmpty(ddlcust.SelectedValue) Then
    param(0) = New SqlParameter("@custnam", ddlcust.SelectedValue)
Else
    param(0) = New SqlParameter("@custnam", DBNull.Value)
End If

Upvotes: 0

NicoTek
NicoTek

Reputation: 1167

The problem is that in the line

Dim params(0) As ReportParameter

you are creating a reportParameter object but not initialazing it. see if it has a constructor then you could call

Dim params(0) As New ReportParameter()

then params won't be nothing

Upvotes: 1

Related Questions