存储过程中的参数太多错误

时间:2013-05-10 20:40:58

标签: asp.net sql vb.net sql-server-2008

我有以下代码,它通过将参数与表中的主键匹配来触发存储过程来删除记录。我通过调试运行代码一切都正确分配,但我一直收到一个错误,指出有太多的参数指定。我认为它与我的存储过程有关,因为正确分配了值。

    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

SQL Server 2008中的存储过程

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

2 个答案:

答案 0 :(得分:0)

您在哪里设置删除命令?我们是否确定它正在调用正确的程序?我想这就是你要做的。检查一下:

SQLDataSource with GridView and CRUD

答案 1 :(得分:0)

不确定这是否能解决问题......但是

您似乎缺少存储过程中的BEGIN。我是新手,但我认为这是必需的。

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

另外,我没有看到你在vb代码中调用SP的位置。

编辑:提供进一步的例子......

我在gv Row Command上的代码看起来像这样......(如果它来自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