Chidi Okeh
Chidi Okeh

Reputation: 1557

Report error, value cannot be null

I am stymied by the above error.

I have a report with a parameter called loc.

The intended purpose of the report is to allow users to select a location from the dropdownlist and then records associated with that location are displayed to the users.

The dropdownlist is getting populated with values just fine.

However, when I select a location from the dropdownlist, I get an error that says:

Value cannot be null. Parameter name: reportParameters

Everything works fine when I pass a value as textbox but not as dropdown.

Any ideas what I am doing wrong?

Below are relevant code. Please forgive me in advance for posting a lot of code.

 '---Dropdownlist control
 <asp:Panel runat="server" ID="pnlLoc" Font-Names="Calibri" BorderStyle="Solid" BorderWidth="1" Style="margin: 0 auto; width:300px;">
             <table>
                 <tr>
                     <td>
                         <asp:Label runat="server" ID="lblLoc" Text="Location: " />
                     </td>
                     <td>
                         <asp:DropDownList runat="server" ID="ddLoc" DataSourceID="dslocator6" AutoPostBack="True">

                         </asp:DropDownList>
                     </td>
                 </tr>
             </table>
          </asp:Panel

 --Report viewer control
   <rsweb:ReportViewer ID="ReportViewer1" runat="server" AsyncRendering="true" SizeToReportContent="true" Font-Names="Arial" 
        Height="675px" Width="750px">
        <LocalReport EnableExternalImages="true" ReportPath=""> 
        </LocalReport> 
    </rsweb:ReportViewer></center>
     <asp:ObjectDataSource ID="LOC" runat="server" SelectMethod="GetData" TypeName="ManageReportsTableAdapters.searchBylocationsTableAdapter">
      <SelectParameters>
        <asp:ControlParameter ControlID="ddLoc" Name="Location" DefaultValue=" " />
      </SelectParameters>
     </asp:ObjectDataSource> 


           --This code populates the ddLoc dropdownlist
               Protected Sub btnLoc_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnLoc.Click
               ReportViewer1.LocalReport.ReportPath = ""
               pnlLoc.Visible = True
               which.Value = "P"
               dslocator6.SelectCommand = "SELECT location FROM Locations ORDER BY [location]"
               ddLoc.DataTextField = "location"
               ddLoc.DataValueField = "location"
              End Sub

           'Define report parameter
           Dim params(0) As ReportParameter


            ReportViewer1.LocalReport.DataSources.Add(New ReportDataSource("locs", LOC.ID))
            ReportViewer1.LocalReport.ReportPath = "locations.rdlc"
            ReportViewer1.LocalReport.Refresh()

            If Not String.IsNullOrEmpty(ddLoc.SelectedValue) Then
                params(0) = New ReportParameter("loc", ddLoc.SelectedValue)
            Else
                params(0) = New ReportParameter("loc", sel, False)
            End If
            ReportViewer1.LocalReport.SetParameters(params) '<-- error points to this line

Upvotes: 0

Views: 1764

Answers (1)

jczmog
jczmog

Reputation: 21

I was getting this error and the problem was me setting an extra index in my array

Dim params(2) As ReportParameter
params(0) = New ReportParameter("SignatureImg", "SomeBase64StringHere")
params(1) = New ReportParameter("SignatureImgMimeType", "image/png")
ReportViewer1.LocalReport.SetParameters(params)

Because of I defined my array like this Dim params(2) As ReportParameter and i was just adding values for the first two index the value on index 3 was null and it was creating the problem.

The solution was just defined the array like this Dim params(1) As ReportParameter.

Upvotes: 1

Related Questions