C # - должен объявить скалярную переменную "@ms_id" - ошибка - PullRequest
0 голосов
/ 01 декабря 2011

Я пишу веб-приложение, которое отслеживает сроки.С помощью этого приложения вы должны иметь возможность обновлять записи, которые сохраняются в базе данных SQL.Однако у меня возникли некоторые проблемы с моим обновлением в моем aspx-файле.

    <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>

Вы можете увидеть мою полную структуру GridView + мой источник данных, связанный с этим GridView.Ничего не написано в моей функции onrowupdating в моем файле с выделенным кодом.

Заранее спасибо

Ответы [ 2 ]

0 голосов
/ 01 декабря 2011

Эта строка;

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

представляется закомментированным и используется в предложении SQL where.

0 голосов
/ 01 декабря 2011

Вы используете @ms_id в предложении where вашего оператора SQL, но строка, которая устанавливает <asp:Parameter ... />, закомментирована. Попробуйте раскомментировать:

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

и попробуйте снова

...