c# -必须声明标量变量"@ms_id"——错误
本文关键字:quot id 错误 @ms 标量 变量 声明 | 更新日期: 2023-09-27 18:16:14
我正在写一个跟踪截止日期的web应用程序。有了这个应用程序,你必须能够更新正在保存在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-structure +我的数据源绑定到这个GridView。在我的代码隐藏文件中的onrowupdate -函数中没有写任何内容。
提前致谢
您在SQL语句的where
子句中使用@ms_id
,但是设置<asp:Parameter ... />
的行被注释掉了。试着取消:
<%-- <asp:Parameter Name="ms_id" Type="String" /> --%>
,再试一次
这一行;
<%-- <asp:Parameter Name="ms_id" Type="String" />--%>
似乎被注释掉了,在SQL where子句中使用。