处理 SqlDataSource <asp:ControlParameter> 部分中的复选框

Handling checkbox in <asp:ControlParameter> section of SqlDataSource

我正在重用一些我在其他页面上取得了很大成功的代码,这里唯一的显着区别是我在过滤器面板中捕获了我没有捕获的复选框的值过去做过。下面提供了代码示例,但我 运行 的症结在于我似乎无法为 SqlDataSource 中列出的参数找到一组可接受的参数。

它抛出的是这样的:"The data types varchar and bit are incompatible in the add operator."

这是我在 asp:ControlParameter 中使用 Type="Boolean" 的时候。我在 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 中的见解将不胜感激。我几乎用尽了我的想法。

我最终更改了数据库 table 将列更改为 varchar(1) 以便我可以在 gridview 中设置所有 BoundFields。然后将我的更新为:

<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,感谢您的输入!这个就完成了!