微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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.

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐