【发布时间】:2012-05-11 14:04:32
【问题描述】:
我将一个经过全面测试的网站移到了我的网络服务器上,并且它不断返回
此不包含具有 ParameterName 'Choices' 的 SqlParameter SqlParameterCollection。
使用 VS 2010 我无法复制此错误,一切正常并通过所有测试。
服务器正在运行 IIS 6 和 net 3.5。我过去使用过它,没有遇到任何问题。该站点是使用 vb.net 在 asp.net 3.5 中构建的。
代码:
<SelectParameters>
<asp:Parameter Name="UserID" Type="Object" />
<asp:ControlParameter ControlID="DropDownList1" Name="Active"
PropertyName="SelectedValue" Type="Boolean" />
<asp:Parameter Name="Choices" Type="String" />
</SelectParameters>
Protected Sub BoarListSQL_Selecting(sender As Object, e As System.Web.UI.WebControls.SqlDataSourceSelectingEventArgs) Handles BoarListSQL.Selecting
e.Command.Parameters("@UserId").Value = userId
e.Command.Parameters("@Active").Value = DropDownList1.SelectedValue.ToString()
e.Command.Parameters("@Choices").Value = lb_breeds.SelectedValue.ToString() 'breedChoice
End Sub
SelectCommand="If @Choices = 'ALL' BEGIN SELECT BoarID,Registration,Breed,Tag1,DOB,Name,BoarStudID,EntryDate,RemovalDate,Reason,Active,Location,BreedingHerdDate,Notes FROM [Table] WHERE ([UserID] = @UserID) AND ([Active] = @Active) END ELSE SELECT BoarID,Registration,Breed,Tag1,DOB,Name,BoarStudID,EntryDate,RemovalDate,Reason,Active,Location,BreedingHerdDate,Notes FROM [Table] WHERE ([UserID] = @UserID) AND ([Active] = @Active) AND ([Breed] = @Choices)"
我在参数列表中有选择,并且在运行选择时添加了一个值。
感谢任何帮助。谢谢。
【问题讨论】:
-
不确定问题,但您可以像这样简化查询:SELECT BoarID, Registration, Breed, Tag1, DOB, Name, BoarStudID, EntryDate, RemovalDate,Reason,Active,Location,BreedingHerdDate,来自 [Table] 的注释 WHERE ([UserID] = @UserID) AND ([Active] = @Active) AND (@Choices = 'ALL' OR [Breed] = @Choices)。嘿,你说“感谢任何帮助”:)
-
我不知道为什么我一开始没有这样写。感谢您的建议。
标签: asp.net sql vb.net listview parameters