SQL parameter not found

Error:

The procedure or function '' expects the parameter '@ Param1', which has not been sent.

Excerpt from the stored procedure:

I have a stored procedure on SQL Server 2012. The procedure looks something like this:

SELECT *
FROM Orders
WHERE Orders.CustomerID = @param1 AND 
    Orders.CustomerJoinDate = @param2

I call this from my code {Using Visual Studio 2008}, like this ...

The calling method in Visual Studios:

First I create an array of parameters that I am going to pass ...

Dim Param() As SqlClient.SqlParameter = 
    New SqlClient.SqlParameter() 
        {
            New SqlClient.SqlParameter("@Param1", Me.cmbFilter1.Text), 
            New SqlClient.SqlParameter("@Param2", Me.cmbFilter2.Text)
        }

Then I look at the parameters and add them to the command that the datareader should execute.

mSQLCmd set to invoke the stored procedure described above ...

mSQLCmd.Parameters.Clear()
mSQLCmd.CommandText = SQLCmd

For Each sParam As SqlClient.SqlParameter In Param
    mSQLCmd.Parameters.AddWithValue(sParam.ParameterName, sParam.Value)
Next

An error occurs when:

I'm trying to run. mSQL.ExecuteReader()Can someone point me in the right direction? I checked that each parameter is included in Param()with the correct values.

SQL Server , , . - vb.

+3
1

, CommandType SqlCommand!

mSQLCmd.CommandText = SQLCmd

// add this line!
mSQLCmd.CommandType = CommandType.StoredProcedure

, , SQL, .

+4

All Articles