我有下面的代码触发存储过程通过匹配参数与表中的主键删除记录。我通过调试运行代码一切正常分配,但我不断收到一个错误,指出有太多的参数指定。我认为这与我的存储过程有关,因为值正在正确分配。存储过程太多的参数错误
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
什么是'sqlds'?你为什么使用'DeleteParameters.Add'而不是命令对象设置为存储过程,只是'Parameters.AddWithValue()'和'cmd.ExecuteNonQuery()'?你需要选择你的VB.Net代码是否要调用临时命令(比如'DELETE')或执行存储过程。 – 2013-05-10 20:45:27
Sqlds是我的sqldatasource。我想只使用存储过程。我应该删除sqldatasource控件并在我的代码中创建连接吗? – 2013-05-10 21:06:14
是的,当您的目标是调用删除单行的存储过程时,为什么要使用数据源?这就像清空整个冰箱扔掉坏牛奶一样。 – 2013-05-10 21:09:28