简体   繁体   English

存储过程的参数过多错误

[英]Too Many Arguments Error with Stored Procedure

I have the below code which is triggering a stored procedure to delete a record by matching the parameter with the primary key in the table. 我有以下代码,该代码通过将参数与表中的主键匹配来触发存储过程以删除记录。 I ran the code through debug ang everything is assigning properly, but I keep receiving an error stating there are too many arguments specified. 我通过debug ang运行了代码,一切都分配正确,但是我不断收到错误消息,指出指定了太多参数。 I think it has something to do with my stored procedure because the values are being assigned properly. 我认为这与我的存储过程有关,因为正确分配了值。

    Protected Sub GridView1_RowCommand(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewCommandEventArgs) Handles GridView1.RowCommand
    Dim CurrentCommand As String = e.CommandName
    Dim CurrentRow As Integer = Int32.Parse(e.CommandArgument.ToString())
    Dim ID As String = GridView1.DataKeys(CurrentRow).Value

    sqlds.DeleteParameters.Add("KeyOpType", ID)
    sqlds.Delete()


End Sub

Stored Procedure in SQL Server 2008 SQL Server 2008中的存储过程

ALTER PROCEDURE [dbo].[GetGenInfo_DeleteMines]
(@KeyOpType int)
AS
Delete FROM GenInfo_OpType
Where KeyOpType = @KeyOpType

Where are you setting your delete command? 您在哪里设置删除命令? Do we know for sure that it is calling the correct procedure? 我们确定它正在调用正确的过程吗? I think this is what you're trying to do . 我认为这就是您要尝试做的。 Check this: 检查一下:

SQLDataSource with GridView and CRUD 带有GridView和CRUD的SQLDataSource

Not sure if this will fix the problem what your having.... but 不知道这是否可以解决您的问题。

It appears you are missing the BEGIN in the stored procedure. 似乎您在存储过程中缺少BEGIN。 I'm new to this, but i think that is required. 我对此并不陌生,但我认为这是必需的。

ALTER PROCEDURE [dbo].[GetGenInfo_DeleteMines]
(@KeyOpType int)
AS
BEGIN <-----------------------------------MISSING THIS
Delete FROM GenInfo_OpType
Where KeyOpType = @KeyOpType

Plus, i don't see where you are calling the SP in the vb code. 另外,我在vb代码中看不到您在哪里调用SP。

EDIT: To give further examples.... 编辑:给出进一步的示例。

My code behind on the gv Row Command would look like this... (if its coming from a button/link on the gv have to add CommandName="SomeCommandName" to the control on the gv) 我在gv行命令上的代码如下所示(如果它来自gv上的按钮/链接,则必须将CommandName =“ SomeCommandName”添加到gv上的控件中)

    Protected Sub gvName_RowCommand(sender As Object, e As System.Web.UI.WebControls.GridViewCommandEventArgs) Handles gvName.RowCommand

        Dim tGrid As GridView = DirectCast(sender, GridView)
        Dim tIndex As Integer = Convert.ToInt32(e.CommandArgument)
        Dim row As GridViewRow = Nothing

Select Case e.CommandName
            Case "SomeCommandName"
                CallToDelete(tGrid.DataKeys(tIndex).Value)
        End Select

    End Sub

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM