SQL statement not being correctly populated from DetailsView (ASPX/C#)
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)"
UpdateCo开发者_如何学JAVAmmand="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?
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 :)
精彩评论