未从 DetailsView (ASPX/C#) 正确填充 SQL 语句

发布于 2024-11-16 03:32:42 字数 1508 浏览 8 评论 0原文

我在 ASPX 页面中有以下代码:

        <asp:DetailsView ID="DetailsView4" runat="server" AutoGenerateRows="False" 
            DataKeyNames="ChangeID,Completed" DataSourceID="SqlDataSource5" Height="50px" 
            Width="125px">
            <Fields>
                <asp:CheckBoxField DataField="Completed" HeaderText="Completed" 
                    SortExpression="Completed" />
                <asp:CommandField ShowEditButton="True" />
            </Fields>
        </asp:DetailsView>


<asp:SqlDataSource ID="SqlDataSource5" runat="server" 
    ConnectionString="<%$ ConnectionStrings:Properties %>" 

    SelectCommand="SELECT * FROM [ATI_CHANGE_REQUESTS] WHERE ([ChangeID] = @ChangeID)" 
    UpdateCommand="UPDATE ATI_CHANGE_REQUESTS SET Completed = @Completed WHERE ChangeID = @ChangeID">
    <SelectParameters>
        <asp:ControlParameter ControlID="grdRequests" Name="ChangeID" 
            PropertyName="SelectedDataKey[1]" Type="Int32" />
    </SelectParameters>
    <UpdateParameters>
        <asp:Parameter Name="Completed" />
        <asp:Parameter Name="ChangeID" />
    </UpdateParameters>
</asp:SqlDataSource>

并且在大多数情况下,它似乎可以正常工作。它从我在 ControlParameter 中引用的 gridview 中提取正确的 ChangeID,但它实际上从未更新任何内容。当我选择了 ChangeID 53 的行时,SQL Profiler 将其执行的命令显示为 UPDATE ATI_CHANGE_REQUESTS SET Completed=0 WHERE ChangeID=53,但无论是否选中 DetailsView4 中的复选框,它总是已完成集=0。我做错了什么?

I've got the following code in an ASPX page:

        <asp:DetailsView ID="DetailsView4" runat="server" AutoGenerateRows="False" 
            DataKeyNames="ChangeID,Completed" DataSourceID="SqlDataSource5" Height="50px" 
            Width="125px">
            <Fields>
                <asp:CheckBoxField DataField="Completed" HeaderText="Completed" 
                    SortExpression="Completed" />
                <asp:CommandField ShowEditButton="True" />
            </Fields>
        </asp:DetailsView>


<asp:SqlDataSource ID="SqlDataSource5" runat="server" 
    ConnectionString="<%$ ConnectionStrings:Properties %>" 

    SelectCommand="SELECT * FROM [ATI_CHANGE_REQUESTS] WHERE ([ChangeID] = @ChangeID)" 
    UpdateCommand="UPDATE ATI_CHANGE_REQUESTS SET Completed = @Completed WHERE ChangeID = @ChangeID">
    <SelectParameters>
        <asp:ControlParameter ControlID="grdRequests" Name="ChangeID" 
            PropertyName="SelectedDataKey[1]" Type="Int32" />
    </SelectParameters>
    <UpdateParameters>
        <asp:Parameter Name="Completed" />
        <asp:Parameter Name="ChangeID" />
    </UpdateParameters>
</asp:SqlDataSource>

And it appears, for the most part, to work correctly. It pulls the correct ChangeID from the gridview I referenced in the ControlParameter, but it never actually updates anything. SQL Profiler shows the command it executes as UPDATE ATI_CHANGE_REQUESTS SET Completed=0 WHERE ChangeID=53 when I've got the row with ChangeID 53 seleced, but whether the checkbox in DetailsView4 is checked or not, it always sets Completed=0. What have I done wrong?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

尬尬 2024-11-23 03:32:42

事实证明,我的 SQL 数据源由于某种未知原因而被破坏,重新创建 SqlDataSource1 完全解决了问题,但我仍然不知道为什么。无论如何,谢谢:)

It turns out my SQL Data Source was hosed for some unknown reason, recreating SqlDataSource1 completely fixed the problem and I still have no idea why. Thanks anyway :)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文