过程或函数在编辑Gridview时指定了太多参数



当我点击编辑txtHours框时,当我点击提交按钮时,我得到了这个错误:

过程或函数UpdateWish指定的参数太多

我对这一切都很陌生,所以我可能在某个地方犯了一个简单的错误。这是为我编写的代码,我已经为不同的应用程序更改了它。如果我能解决这个错误,应该都能工作。我使用ASP。净,VB。Net和SQL Server。在VB文件中没有应该影响这一点的代码,所以我没有包括它。谢谢你的帮助。

前端

<asp:TextBox ID="txtWishText" runat="server" style="padding-left:20px; padding-right:20px; text-align:center;" Columns="5" MaxLength="5" Font-Size="Large" Height="28px" AutoComplete="off"></asp:TextBox>
&nbsp;&nbsp;<br>
<asp:ImageButton ID="btnSubmitWish" runat="server" class="BackNextButton" style="margin-top:7px;" ImageUrl="~/files/images/icons/submitButton.gif" ValidationGroup="Wish" />
<br />
<asp:RequiredFieldValidator ID="rqdWish" runat="server" 
ErrorMessage="Enter Hours Worked" ValidationGroup="Wish" 
CssClass="error" ControlToValidate="txtWishText" Display="Dynamic"></asp:RequiredFieldValidator>
<br />
<h2 style="font-size:16px; color:#333333; font-family: 'Seymour One', sans-serif; text-align:center;">My Hours: <asp:Label ID="LabelTotalHours" runat="server" ></asp:Label></h2>
<asp:SqlDataSource ID="DSMyWishes" runat="server" 
ConnectionString="<%$ ConnectionStrings:DBConnectionString %>" 
DeleteCommand="RemoveWish" DeleteCommandType="StoredProcedure" 
SelectCommand="SelectFullWishesByAccount" 
SelectCommandType="StoredProcedure" 
UpdateCommand="UpdateWish" UpdateCommandType="StoredProcedure">
<DeleteParameters>
<asp:Parameter Name="wishID" Type="Int32" />
</DeleteParameters>
<SelectParameters>
<asp:Parameter Name="name" DbType="String" />
</SelectParameters>
<UpdateParameters>
<asp:Parameter Name="wishID" Type="Int32" />
<asp:Parameter Name="dailyHours" Type="Decimal" />
</UpdateParameters>
</asp:SqlDataSource>
<asp:GridView ID="gdvMyWishes" runat="server" CssClass="mGrid" DataSourceID="DSMyWishes" width="100%" AutoGenerateColumns="False" DataKeyNames="wishID">
<AlternatingRowStyle CssClass="alt" />
<Columns>
<asp:TemplateField HeaderText="Date" SortExpression="wishText">
<ItemTemplate>                      
<asp:Label ID="LabelDate" font-size="1.0em"  runat="server" Text='<%# Bind("dateInserted") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>

<asp:TemplateField HeaderText="Hours" SortExpression="wishText">
<EditItemTemplate>
<asp:TextBox ID="txtHours" runat="server" Columns="40" MaxLength="40" Text='<%# Bind("dailyHours") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label1" font-size="1.0em"  runat="server" Text='<%# Bind("dailyHours") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>

<asp:CommandField ShowDeleteButton="True" ShowEditButton="True" ButtonType="Link"
DeleteImageUrl="~/files/images/icons/deleteIcon.png" EditImageUrl="~/files/Images/icons/editIcon.png" UpdateImageUrl="~/files/Images/icons/submitIcon.png" CancelImageUrl="~/files/Images/icons/backIcon.png"/>
</Columns>
<EmptyDataTemplate>
No hours recorded
</EmptyDataTemplate>
</asp:GridView>
SQL Server存储过程:
ALTER PROCEDURE [UpdateWish]
@wishID     int,
@dailyHours decimal(10,2)
AS
BEGIN
SET NOCOUNT ON;
UPDATE tblWishes
SET dailyHours = @dailyHours
WHERE wishID = @wishID
END

根据您的代码,它看起来很适合传递2个更新参数,并且在存储过程中也有2个参数。

同样用于选择和删除与CommandType.StoredProcedure工作良好?

否则,您应该首先按照以下方法尝试不使用存储过程。

  • 删除UpdateCommandType="StoredProcedure"并在UpdateCommand中设置更新查询
  • 代码:

<asp:SqlDataSource ID="DSMyWishes" runat="server" 
ConnectionString="<%$ ConnectionStrings:DBConnectionString %>" 
DeleteCommand="RemoveWish" DeleteCommandType="StoredProcedure" 
SelectCommand="SelectFullWishesByAccount" 
SelectCommandType="StoredProcedure" 
UpdateCommand="UPDATE tblWishes SET dailyHours = @dailyHours WHERE wishID = @wishID">

最新更新