문제

I'm writing an web-app that keeps track of deadlines. With this app you have to be able to update records that are being saved in an SQL DB. However I'm having some problem with my update in my aspx-file.

    <asp:GridView ID="gv_editMilestones" runat="server" DataSourceID="sql_ds_milestones" 
    CellPadding="4" ForeColor="#333333" GridLines="None" Font-Size="Small" 
    AutoGenerateColumns="False" DataKeyNames="id" Visible="false"
    onrowupdated="gv_editMilestones_RowUpdated" 
    onrowupdating="gv_editMilestones_RowUpdating" 
    onrowediting="gv_editMilestones_RowEditing">
    <RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
    <Columns>
        <asp:CommandField ShowEditButton="True" />
        <asp:BoundField DataField="id" HeaderText="id" SortExpression="id" 
            ReadOnly="True" Visible="false"/>
        <asp:BoundField DataField="ms_id" HeaderText="ms_id" 
            SortExpression="ms_id" ReadOnly="True"/>
        <asp:BoundField DataField="ms_description" HeaderText="ms_description" 
            SortExpression="ms_description"/>  
<%--        <asp:BoundField DataField="ms_resp_team" HeaderText="ms_resp_team" 
            SortExpression="ms_resp_team"/>--%>
        <asp:TemplateField HeaderText="ms_resp_team" SortExpression="ms_resp_team">
            <ItemTemplate>
                <%# Eval("ms_resp_team") %>
            </ItemTemplate>
            <EditItemTemplate>
                <asp:DropDownList ID="DDL_ms_resp_team" runat="server"
                    DataSourceID="sql_ds_ms_resp_team" DataTextField="team_name"
                    DataValueField="id">
                    <%--SelectedValue='<%# Bind("ms_resp_team") %>'--%>
                </asp:DropDownList>
            </EditItemTemplate>
        </asp:TemplateField>
        <asp:BoundField DataField="ms_focal_point" HeaderText="ms_focal_point" 
            SortExpression="ms_focal_point" />
        <asp:BoundField DataField="ms_exp_date" HeaderText="ms_exp_date" 
            SortExpression="ms_exp_date" DataFormatString="{0:d}"/>
        <asp:BoundField DataField="ms_deal" HeaderText="ms_deal" 
            SortExpression="ms_deal" ReadOnly="True"/>
        <asp:CheckBoxField DataField="ms_active" HeaderText="ms_active" 
            SortExpression="ms_active"/>
    </Columns>
    <FooterStyle BackColor="#CCCC99" />
    <PagerStyle BackColor="#F7F7DE" ForeColor="Black" HorizontalAlign="Right" />
    <SelectedRowStyle BackColor="#CE5D5A" Font-Bold="True" ForeColor="White" />
    <HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
    <AlternatingRowStyle BackColor="White" />
    <EditRowStyle BackColor="#999999" />
</asp:GridView>
<asp:SqlDataSource ID="sql_ds_milestones" runat="server" 
    ConnectionString="<%$ ConnectionStrings:testServer %>" 
    SelectCommand="SELECT [id]
                          ,[ms_id]
                          ,[ms_description]
                          ,(SELECT [team_name] FROM [NSBP].[dbo].[tbl_teams] as teams
                            WHERE milestones.[ms_resp_team] = teams.[id]) as 'ms_resp_team'
                          ,[ms_focal_point]
                          ,[ms_exp_date]
                          ,(SELECT [deal] FROM [NSBP].[dbo].[tbl_deals] as deals
                            WHERE milestones.[ms_deal] = deals.[id]) as 'ms_deal'
                          ,[ms_active]
                          FROM [NSBP].[dbo].[tbl_milestones] as milestones"
    UpdateCommand="UPDATE [NSBP].[dbo].[tbl_milestones]
                   SET [ms_description] = @ms_description
                   ,[ms_focal_point] = @ms_focal_point
                   ,[ms_active] = @ms_active
                   WHERE [ms_id] = @ms_id">
    <UpdateParameters>
        <asp:Parameter Name="ms_description" Type="String" />
<%--            <asp:Parameter Name="ms_resp_team" Type="String" />--%>
        <asp:Parameter Name="ms_focal_point" Type="String" />
        <asp:Parameter Name="ms_exp_date" Type="DateTime" />
        <asp:Parameter Name="ms_active" Type="Boolean" />
<%--            <asp:Parameter Name="ms_id" Type="String" />--%>
    </UpdateParameters>
</asp:SqlDataSource>

You can see my complete GridView-structure + my datasource bound to this GridView. There is nothing written in my onrowupdating-function in my code-behind file.

Thx in advance

도움이 되었습니까?

해결책

You are using @ms_id in the where clause of your SQL Statement, but the line that sets that <asp:Parameter ... /> is commented out. Try uncommenting:

<%-- <asp:Parameter Name="ms_id" Type="String" /> --%>

and try again

다른 팁

This line;

<%--            <asp:Parameter Name="ms_id" Type="String" />--%>

appears to be commented out and is used in the SQL where clause.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top