我重复使用了一些我在其他网页上取得了很大成功的代码,这里唯一的重要区别是我在过滤器面板中捕获了Checkbox的价值我过去没做过。代码示例如下所示,但我遇到的关键是我似乎无法为SqlDataSource中列出的列表找到一组可接受的参数。
它抛出的是:"数据类型varchar和bit在add运算符中是不兼容的。"
这是我使用Type =" Boolean"在asp:ControlParameter中。我在asp:ControlParameter中尝试了很多类型和其他语法但没有成功。
<% - 来自过滤器面板 - %>
<% - SqlDataSource - %>
<asp:SqlDataSource runat="server" ID="SqlDataSource1" CancelSelectOnNullParameter="false" ConnectionString='<%$ ConnectionStrings:csrConnectionString %>' DeleteCommand="DELETE FROM [csr_refdata_ip360_HostVulnerabilityCSV] WHERE [RecID] = @RecID" InsertCommand="INSERT INTO [csr_refdata_ip360_HostVulnerabilityCSV] ([DNS Name], [NetBIOS Name], [IP], [OS], [Vulnerability Score], [Vulnerability], [Vulnerability ID], [TicketNumber], [TicketClosed], [AssetID], [ExceptionID], [Notes]) VALUES (@DNS_Name, @NetBIOS_Name, @IP, @OS, @Vulnerability_Score, @Vulnerability, @Vulnerability_ID, @TicketNumber, @TicketClosed, @AssetID, @ExceptionID, @Notes)" SelectCommand="SELECT RecID, [DNS Name] AS DNS_Name, [NetBIOS Name] AS NetBIOS_Name, IP, OS, [Vulnerability Score] AS Vulnerability_Score, Vulnerability, [Vulnerability ID] AS Vulnerability_ID, TicketNumber, TicketClosed, AssetID, ExceptionID, Notes FROM csr_refdata_ip360_HostVulnerabilityCSV WHERE (Excepted = @Excepted) AND (RTRIM(LTRIM(ISNULL(@RecID, ''))) = '' OR RecID LIKE '%' + @RecID + '%') AND (RTRIM(LTRIM(ISNULL(@DNS_Name, ''))) = '' OR [DNS Name] LIKE '%' + @DNS_Name + '%') AND (RTRIM(LTRIM(ISNULL(@NetBIOS_Name, ''))) = '' OR [NetBIOS Name] LIKE '%' + @NetBIOS_Name + '%') AND (RTRIM(LTRIM(ISNULL(@IP, ''))) = '' OR IP LIKE '%' + @IP + '%') AND (RTRIM(LTRIM(ISNULL(@OS, ''))) = '' OR OS LIKE '%' + @OS + '%') AND (RTRIM(LTRIM(ISNULL(@Vulnerability_Score, ''))) = '' OR [Vulnerability Score] LIKE '%' + @Vulnerability_Score + '%') AND (RTRIM(LTRIM(ISNULL(@Vulnerability, ''))) = '' OR Vulnerability LIKE '%' + @Vulnerability + '%') AND (RTRIM(LTRIM(ISNULL(@Vulnerability_ID, ''))) = '' OR [Vulnerability ID] LIKE '%' + @Vulnerability_ID + '%') AND (RTRIM(LTRIM(ISNULL(@TicketNumber, ''))) = '' OR TicketNumber LIKE '%' + @TicketNumber + '%') AND (RTRIM(LTRIM(ISNULL(@TicketClosed, ''))) = '' OR TicketClosed LIKE '%' + @TicketClosed + '%') AND (RTRIM(LTRIM(ISNULL(@Notes, ''))) = '' OR Notes LIKE '%' + @Notes + '%') AND (RTRIM(LTRIM(ISNULL(@AssetID, ''))) = '' OR AssetID LIKE '%' + @AssetID + '%') AND (RTRIM(LTRIM(ISNULL(@ExceptionID, ''))) = '' OR ExceptionID LIKE '%' + @ExceptionID + '%') ORDER BY Vulnerability_Score DESC, Vulnerability, NetBIOS_Name" UpdateCommand="UPDATE [csr_refdata_ip360_HostVulnerabilityCSV] SET [DNS Name] = @DNS_Name, [NetBIOS Name] = @NetBIOS_Name, [IP] = @IP, [OS] = @OS, [Vulnerability Score] = @Vulnerability_Score, [Vulnerability] = @Vulnerability, [Vulnerability ID] = @Vulnerability_ID, [TicketNumber] = @TicketNumber, [TicketClosed] = @TicketClosed, [AssetID] = @AssetID, [ExceptionID] = @ExceptionID, [Notes] = @Notes WHERE [RecID] = @RecID">
<DeleteParameters>
<asp:Parameter Name="RecID" Type="Int32"></asp:Parameter>
</DeleteParameters>
<InsertParameters>
<asp:Parameter Name="DNS_Name" Type="String"></asp:Parameter>
<asp:Parameter Name="NetBIOS_Name" Type="String"></asp:Parameter>
<asp:Parameter Name="IP" Type="String"></asp:Parameter>
<asp:Parameter Name="OS" Type="String"></asp:Parameter>
<asp:Parameter Name="Vulnerability_Score" Type="Int16"></asp:Parameter>
<asp:Parameter Name="Vulnerability" Type="String"></asp:Parameter>
<asp:Parameter Name="Vulnerability_ID" Type="Int32"></asp:Parameter>
<asp:Parameter Name="TicketNumber" Type="Int32"></asp:Parameter>
<asp:Parameter Name="TicketClosed" Type="Boolean"></asp:Parameter>
<asp:Parameter Name="AssetID" Type="Int64"></asp:Parameter>
<asp:Parameter Name="ExceptionID" Type="Int32"></asp:Parameter>
<asp:Parameter Name="Notes" Type="String"></asp:Parameter>
</InsertParameters>
<SelectParameters>
<asp:Parameter DefaultValue="N" Name="Excepted" Type="String"></asp:Parameter>
<asp:ControlParameter Name="RecID" ControlID="RecID_Tbx" Type="Int32" ConvertEmptyStringToNull="true" />
<asp:ControlParameter Name="DNS_Name" ControlID="DNSName_Tbx" Type="String" ConvertEmptyStringToNull="true"/>
<asp:ControlParameter Name="NetBIOS_Name" ControlID="NetBIOSName_Tbx" Type="String" ConvertEmptyStringToNull="true" />
<asp:ControlParameter Name="IP" ControlID="IP_Tbx" Type="String" ConvertEmptyStringToNull="true"/>
<asp:ControlParameter Name="OS" ControlID="OS_Tbx" Type="String" ConvertEmptyStringToNull="true" />
<asp:ControlParameter Name="Vulnerability_Score" ControlID="Vulnerability_Tbx" Type="Int16" ConvertEmptyStringToNull="true" />
<asp:ControlParameter Name="Vulnerability" ControlID="Vulnerability_Tbx" Type="String" ConvertEmptyStringToNull="true" />
<asp:ControlParameter Name="Vulnerability_ID" ControlID="VulnerabilityID_Tbx" Type="Int32" ConvertEmptyStringToNull="true" />
<asp:ControlParameter Name="TicketNumber" ControlID="TicketNum_Tbx" Type="String" ConvertEmptyStringToNull="true" />
<%--<%--<%-- This is the problem line below --%>--%>--%>
<asp:ControlParameter Name="TicketClosed" ControlID="TicketClosed_ChBox" Type="Boolean" ConvertEmptyStringToNull="true" />
<asp:ControlParameter Name="Notes" ControlID="Notes_Tbx" Type="String" ConvertEmptyStringToNull="true" />
<asp:ControlParameter Name="AssetID" ControlID="AssetID_Tbx" Type="Int64" ConvertEmptyStringToNull="true" />
<asp:ControlParameter Name="ExceptionID" ControlID="ExceptionID_Tbx" Type="String" ConvertEmptyStringToNull="true" />
</SelectParameters>
<UpdateParameters>
<asp:Parameter Name="DNS_Name" Type="String"></asp:Parameter>
<asp:Parameter Name="NetBIOS_Name" Type="String"></asp:Parameter>
<asp:Parameter Name="IP" Type="String"></asp:Parameter>
<asp:Parameter Name="OS" Type="String"></asp:Parameter>
<asp:Parameter Name="Vulnerability_Score" Type="Int16"></asp:Parameter>
<asp:Parameter Name="Vulnerability" Type="String"></asp:Parameter>
<asp:Parameter Name="Vulnerability_ID" Type="Int32"></asp:Parameter>
<asp:Parameter Name="TicketNumber" Type="Int32"></asp:Parameter>
<asp:Parameter Name="TicketClosed" Type="Boolean"></asp:Parameter>
<asp:Parameter Name="AssetID" Type="Int64"></asp:Parameter>
<asp:Parameter Name="ExceptionID" Type="Int32"></asp:Parameter>
<asp:Parameter Name="Notes" Type="String"></asp:Parameter>
<asp:Parameter Name="RecID" Type="Int32"></asp:Parameter>
</UpdateParameters>
</asp:SqlDataSource>
有关如何将此复选框正确填入我的ControlParameter的任何见解将非常感激。我的想法几乎耗尽了。
答案 0 :(得分:1)
我最终改变了db表,将列更改为varchar(1),以便我可以在gridview中设置所有BoundField。然后将我更新为:
<SelectParameters>
<asp:Parameter DefaultValue="N" Name="Excepted" Type="String"></asp:Parameter>
<asp:ControlParameter Name="RecID" ControlID="RecID_Tbx" Type="String" ConvertEmptyStringToNull="true" />
<asp:ControlParameter Name="DNS_Name" ControlID="DNSName_Tbx" Type="String" ConvertEmptyStringToNull="true"/>
<asp:ControlParameter Name="NetBIOS_Name" ControlID="NetBIOSName_Tbx" Type="String" ConvertEmptyStringToNull="true" />
<asp:ControlParameter Name="IP" ControlID="IP_Tbx" Type="String" ConvertEmptyStringToNull="true"/>
<asp:ControlParameter Name="OS" ControlID="OS_Tbx" Type="String" ConvertEmptyStringToNull="true" />
<asp:ControlParameter Name="Vulnerability_Score" ControlID="VulnerabilityScore_Tbx" Type="String" ConvertEmptyStringToNull="true" />
<asp:ControlParameter Name="Vulnerability" ControlID="Vulnerability_Tbx" Type="String" ConvertEmptyStringToNull="true" />
<asp:ControlParameter Name="Vulnerability_ID" ControlID="VulnerabilityID_Tbx" Type="String" ConvertEmptyStringToNull="true" />
<asp:ControlParameter Name="TicketNumber" ControlID="TicketNum_Tbx" Type="String" ConvertEmptyStringToNull="true" />
<asp:ControlParameter Name="TicketClosed" ControlID="TicketClosed_Tbx" Type="String" ConvertEmptyStringToNull="true" />
<asp:ControlParameter Name="Notes" ControlID="Notes_Tbx" Type="String" ConvertEmptyStringToNull="true" />
<asp:ControlParameter Name="AssetID" ControlID="AssetID_Tbx" Type="String" ConvertEmptyStringToNull="true" />
<asp:ControlParameter Name="ExceptionID" ControlID="ExceptionID_Tbx" Type="String" ConvertEmptyStringToNull="true" />
现在一切正常...... MethodMan,感谢您的投入!这个已经完成了!