报告错误,值不能为null



我被上述错误所困扰。

我有一个参数为loc的报告。

该报告的目的是允许用户从下拉列表中选择一个位置,然后向用户显示与该位置相关联的记录。

下拉列表中的值填充得很好。

然而,当我从下拉列表中选择一个位置时,我会收到一个错误,上面写着:

值不能为null。参数名称:reportParameters

当我将值作为文本框而不是下拉框传递时,一切都很好。

你知道我做错了什么吗?

以下是相关代码。请提前原谅我发布了很多代码。

 '---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

我收到了这个错误,问题是我在数组中设置了一个额外的索引

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

因为我像这样定义了我的数组Dim params(2)作为ReportParameter,而我只是为前两个索引添加值,所以索引3上的值为null,这就造成了问题。

解决方案只是将数组定义为Dim params(1)As ReportParameter。

相关内容

最新更新