加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > asp.Net > 正文

asp.net – 当我尝试从数据库中删除一行时,我收到了太多的参数错

发布时间:2020-12-16 07:01:27 所属栏目:asp.Net 来源:网络整理
导读:我创建了一个包含简单存储过程的数据库,用于删除,插入,选择和更新数据库的三个表中的记录.除了我的删除语句之外,它们都有效.当我尝试它时,我得到一个过程或函数有太多的参数消息.我尝试删除它拥有的一个参数,最后删除了所有表的记录,而不是我所针对的记录.我
我创建了一个包含简单存储过程的数据库,用于删除,插入,选择和更新数据库的三个表中的记录.除了我的删除语句之外,它们都有效.当我尝试它时,我得到一个过程或函数有太多的参数消息.我尝试删除它拥有的一个参数,最后删除了所有表的记录,而不是我所针对的记录.我究竟做错了什么?我有一种感觉错误在我的SQL脚本中,但我不知道我可以做些什么来使其工作.

消息:

Procedure or function Delete_Special has too many arguments specified.

我的SQL脚本:

CREATE PROCEDURE [Delete_Special]
    @ThisID INT
AS
    DELETE FROM [Daily_Specials]
    WHERE @ThisID = [ID]
GO

调用存储过程的事件:

Protected Sub BTN_DeleteEvt_Click(sender As Object,e As EventArgs)
    SQL_Specials.Delete()
End Sub

删节标记:

<asp:SqlDataSource ID="SQL_Specials" runat="server" DeleteCommand="Delete_Special" DeleteCommandType="StoredProcedure">
    <DeleteParameters>
        <asp:ControlParameter ControlID="GV_Eagles_Specials" Name="ThisID" PropertyName="SelectedIndex"
            Type="Int32" />
    </DeleteParameters>
</asp:SqlDataSource>
<asp:GridView ID="GV_Eagles_Specials" runat="server" DataSourceID="SQL_Specials" AutoGenerateColumns="False">
    <Columns>
        <asp:TemplateField>
            <ItemTemplate>
                <asp:Button ID="BTN_EditSpecial" runat="server" CssClass="BigText" Text="Edit" OnClick="BTN_EditEvent_Click" />
            </ItemTemplate>
        </asp:TemplateField>
        <asp:BoundField DataField="Date" HeaderText="Date" SortExpression="Date" HtmlEncode="False" DataFormatString="{0:MM/dd/yyyy}" />
        <asp:BoundField DataField="Special" HeaderText="Special" SortExpression="Special" HtmlEncode="False" />
        <asp:BoundField DataField="Side" HeaderText="Side" SortExpression="Side" HtmlEncode="False" />
        <asp:BoundField DataField="Special_Price" HeaderText="Special Price" SortExpression="Special_Price" HtmlEncode="False" />
        <asp:BoundField DataField="Soup" HeaderText="Soup" SortExpression="Soup" HtmlEncode="False" />
        <asp:BoundField DataField="Soup_Price" HeaderText="Soup Price" SortExpression="Soup_Price" HtmlEncode="False" />
        <asp:TemplateField ShowHeader="False">
            <ItemTemplate>
                <asp:Button ID="BTN_DeleteEvt" runat="server" CausesValidation="False" CommandName="Delete" Text="Delete" CssClass="BigText" OnClick="BTN_DeleteEvt_Click" />
            </ItemTemplate>
        </asp:TemplateField>
    </Columns>
</asp:GridView>

解决方法

看起来问题不在于SQL Server.我正在浏览这个问题的MSDN和 I found this

在答案中:

So,I’m thrashing around with the stored proc since it looks like the error is originating from there. One interesting thing that I notice is that the stored proc runs just fine from SQL Query Analyzer and returns the autogenerated row number like it’s supposed to. However,when run from within Visual Studio,I get the same @Identity error and the stored proc neither adds a table row nor returns a row number.

I borrow a copy of Professional SQL Server 2000 Programming by Robert Vieira. Good ‘ol Roberto has the following to say on page 367:

“You must use the OUTPUT keyword when you call the sproc,much as you did when you declared the sproc. This gives SQL Server advance warning about the special handling that parameter will require. Be aware,however,that forgetting to include the OUTPUT keyword won’t create a runtime error,but the value for the output parameter won’t be moved into your variable (you’ll just wind up with what was already there – most likely a NULL value). …”

Since this sounded a lot like the @Identity error I was getting,I took a closer look at the @Identity definition in the stored proc on the assumption that something is failing to let SQL Server know in advance that the stored proc has an OUTPUT return value. The variable initialization dialog box that pops up when you run the stored proc has a dropdown box for initializing the value of @Identity which seems wierd because it’s an OUTPUT variable. The two options are <DEFAULT> (the default setting in the dropdown) and <NULL>.

More as a result of being out of ideas than any rational thought process,I change <DEFAULT> to <NULL> in the dialog box and run the stored proc.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读