1

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

    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
4

2 回答 2

0

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

于 2013-05-10T21:02:22.890 回答
0

Not sure if this will fix the problem what your having.... but

It appears you are missing the BEGIN in the stored procedure. 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.

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)

    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
于 2013-05-10T21:02:56.403 回答