C# - 必须声明标量变量“@ms_id” - 错误

发布于 2024-12-19 11:04:47 字数 4426 浏览 6 评论 0原文

我正在编写一个跟踪截止日期的网络应用程序。使用此应用程序,您必须能够更新保存在 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 函数中没有写入任何内容。

提前谢谢

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

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

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

发布评论

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

评论(2

世界和平 2024-12-26 11:04:47

您在 SQL 语句的 where 子句中使用 @ms_id,但设置 被注释掉。尝试取消注释:

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

然后重试

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

茶色山野 2024-12-26 11:04:47

这条线;

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

似乎被注释掉并在 SQL where 子句中使用。

This line;

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

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

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