报告错误,值不能为空

时间:2014-10-02 14:41:19

标签: asp.net vb.net reportviewer reportparameter

我因上述错误而受阻。

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

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

下拉列表的填充值很好。

但是,当我从下拉列表中选择一个位置时,我收到一条错误消息:

值不能为空。参数名称: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

1 个答案:

答案 0 :(得分:1)

我遇到此错误,问题是我在数组中设置了额外的索引

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上的值为空,这就是问题所在。

该解决方案只是将像Dim params(1)这样的数组定义为ReportParameter。