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. 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
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:
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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.