过程或函数'p_xxx'指定了太多参数

时间:2014-02-06 08:14:54

标签: vb.net

我在这一行收到错误:sqlDataAdapDelProtocol.Fill(dsDelProtocol, "dsProtocols"),我不明白为什么。错误状态:Procedure or function p_GetLinkedProcuduresProtocol has too many arguments specified

    Protected Sub btnDeletePTC_Click(ByVal sender As Object, ByVal e As EventArgs)

    Dim sqlString As String = String.Empty
    Dim PTC_ID As Integer
    sqlString = "p_GetLinkedProcuduresProtocol"

    Dim sqlConnDelProtocol As New SqlClient.SqlConnection(typicalConnectionString("MyConn").ConnectionString)
    sqlConnDelProtocol.Open()

    Dim sqlDataAdapDelProtocol As New SqlClient.SqlDataAdapter(sqlString, sqlConnDelProtocol)
    sqlDataAdapDelProtocol.SelectCommand.CommandType = CommandType.StoredProcedure


    Dim sqlParProtocolName As New SqlClient.SqlParameter("@PTC_ID", SqlDbType.Int, 255)
          sqlDataAdapDelProtocol.SelectCommand.Parameters.Add(sqlParProtocolName)

    Dim dsDelProtocol As New DataSet
    Dim MessageAud = "Are you sure you want to delete this question, the question is linked to:"
    Dim MessageNoAud = "Are you sure you want to delete this question"


    sqlDataAdapDelProtocol.SelectCommand.Parameters.AddWithValue("PTC_ID", PTC_ID)
    sqlDataAdapDelProtocol.Fill(dsDelProtocol, "dsProtocols")

    If dsDelProtocol.Tables("dsProtocols").Rows.Count > 0 Then
        lblMessageSure.Text = (CType(MessageAud, String))
        For Each dr As DataRow In dsDelProtocol.Tables(0).Rows
            lblAudits = (dr("dsProtocols"))
        Next
    Else
        lblMessageSure.Text = (CType(MessageNoAud, String))
    End If

    Dim success As Boolean = False

    Dim btnDelete As Button = TryCast(sender, Button)
    Dim row As GridViewRow = DirectCast(btnDelete.NamingContainer, GridViewRow)

          Dim cmdDelete As New SqlCommand("p_deleteProtocolStructure")
    cmdDelete.CommandType = CommandType.StoredProcedure
    cmdDelete.Parameters.AddWithValue("PTC_ID", PTC_ID)

    Call DeleteProtocol(PTC_ID)

    conn = NewSqlConnection(connString, EMP_ID)
    cmdDelete.Connection = conn

    If Not conn Is Nothing Then
        If conn.State = ConnectionState.Open Then
            Try
                success = cmdDelete.ExecuteNonQuery()
                Call UpdateProtocolNumbering(PTS_ID)
                txtAddPTCNumber.Text = GetNextNumber(PTS_ID)
                Page.ClientScript.RegisterClientScriptBlock(Me.GetType(), "TreeView", _
                "<script language='javascript'>" & _
                "   parent.TreeView.location='TreeView.aspx?MainScreenURL=Protocols.aspx&PTS_ID=" & PTS_ID & "';" & _
                "</script>")

                conn.Close()
            Catch ex As Exception
                success = False
                conn.Close()
                Throw ex
            End Try
        End If
    End If

    If success = True Then
        Call GenerateQuestionsGrid()
        Call Message(Me, "pnlMessage", "Question successfully deleted.", Drawing.Color.Green)
    Else
        Call Message(Me, "pnlMessage", "Failed to delete Question.", Drawing.Color.Red)
    End If
End Sub

1 个答案:

答案 0 :(得分:1)

您要添加两次相同的参数,一次没有值,然后是一个值。不要再添加它,而是在已有的参数上设置值。

替换它:

sqlDataAdapDelProtocol.SelectCommand.Parameters.AddWithValue("PTC_ID", PTC_ID)

用这个:

sqlParProtocolName.Vaue = PTC_ID

附注:始终使用@启动Sql Server的参数名称。参数构造函数将添加它,如果它不存在那么它将在没有它的情况下工作,但这是一个未记录的特性,因此在将来的版本中可能会改变。