none
The SqlParameterCollection only accepts non-null SqlParameter type objects. RRS feed

  • Question

  •      

    Hi Expert,

    Need help in your end, below is my code and the error shown in line 200 which is  

    • commands.Parameters.AddRange(params). How can I fix this

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click

            Dim params(9) As SqlParameter
            params(0) = New SqlParameter("@WSTransactions", SqlDbType.Char)
            params(0).Value = TextBox1.Text
            params(1) = New SqlParameter("@ItemNo", SqlDbType.Char)
            params(1).Value = ComboBox2.Text
            params(2) = New SqlParameter("@Description", SqlDbType.VarChar)
            params(2).Value = ComboBox3.Text
            params(3) = New SqlParameter("@Requestor", SqlDbType.Char)
            params(3).Value = ComboBox1.Text
            params(4) = New SqlParameter("@QtyRequested", SqlDbType.Int)
            params(4).Value = TextBox3.Text
            params(5) = New SqlParameter("@DateRequested", SqlDbType.DateTime)
            params(5).Value = DateTimePicker1.Text
            params(6) = New SqlParameter("@DateNeeded", SqlDbType.DateTime)
            params(6).Value = DateTimePicker2.Text
            params(7) = New SqlParameter("@DaysAlloted", SqlDbType.Int)
            params(7).Value = Label6.Text
            params(8) = New SqlParameter("@Remarks", SqlDbType.VarChar)
            params(8).Value = TextBox4.Text
            Dim commands As New SqlCommand
            commands.Connection = connection
            commands.CommandType = CommandType.StoredProcedure
            commands.CommandText = " EXEC spWSLIPTRANSACTIONS"
            commands.Parameters.AddRange(params)

            connection.Open()
            commands.ExecuteNonQuery()
            connection.Close()

    End Sub

    Tuesday, August 7, 2018 1:56 AM

All replies

  • Try this modification:

       Dim params(8) As SqlParameter

    • Proposed as answer by Alex Li-MSFT Tuesday, August 7, 2018 6:20 AM
    Tuesday, August 7, 2018 4:40 AM
  • Hi

    Do you resolve the issue? I think Viorel_'s reply can solve your problem.

    Best Regards,

    Alex


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Wednesday, August 8, 2018 2:26 AM
  • Hi Alex,

    NO is not, I made some modifications as follows and it works but the problems shows that too many 

    arguements specified

    Try


                Dim reader As SqlDataReader
                command.Connection = connection
                command.CommandType = CommandType.StoredProcedure
                command.CommandText = "spWSLIPTRANSACTIONS"
                command.Parameters.Add("@WSTransactions", Data.SqlDbType.Char)
                command.Parameters("@WSTransactions").Value = TextBox1.Text
                command.Parameters.Add("@ItemNo", Data.SqlDbType.Char)
                command.Parameters("@ItemNo").Value = ComboBox2.Text
                command.Parameters.Add("@Description", Data.SqlDbType.VarChar)
                command.Parameters("@Description").Value = ComboBox3.Text
                command.Parameters.Add("@Requestor", Data.SqlDbType.Char)
                command.Parameters("@Requestor").Value = ComboBox1.Text

                command.Parameters.Add("@QtyRequested", Data.SqlDbType.Int)
                command.Parameters("@QtyRequested").Value = TextBox3.Text

                command.Parameters.Add("@DateRequested", Data.SqlDbType.DateTime)
                command.Parameters("@DateRequested").Value = DateTimePicker1.Text

                command.Parameters.Add("@DateNeeded", Data.SqlDbType.DateTime)
                command.Parameters("@DateNeeded").Value = DateTimePicker2.Text
                command.Parameters.Add("@DaysAlloted", Data.SqlDbType.Int)
                command.Parameters("@DaysAlloted").Value = Label6.Text
                command.Parameters.Add("@Remarks", Data.SqlDbType.Char)
                command.Parameters("@Remarks").Value = TextBox4.Text

                connection.Open()
                reader = command.ExecuteReader()
                reader.Close()

    Wednesday, August 8, 2018 9:55 AM
  • Yes I did bu the error show:

    System.Data.SqlClient.SqlException: 'Procedure or function spWSLIP has too many arguments specified.'

    Once when I make add again, in yhe same item

    Wednesday, August 8, 2018 10:04 AM
  • Hi,

    I think your question is similar to the following two people, I hope they can help you.

    https://stackoverflow.com/questions/19641849/procedure-or-function-has-too-many-arguments-specified-but-it-doesnt

    https://stackoverflow.com/questions/17292705/procedure-or-function-has-too-many-arguments-specified

    Best Regards,

    Alex


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Thursday, August 9, 2018 3:50 AM