tags:

views:

24

answers:

1

Ok, I'm stumped here - the folowing code errors with Procedure or function 'importsp_CreateDiallerBatch' expects parameter '@BatchName', which was not supplied

        Dim cmd As SqlCommand = New SqlCommand()
        cmd.CommandText = "importsp_CreateDiallerBatch"
        cmd.Connection = cnSQL
        cmd.Parameters.AddWithValue("@BatchName", BatchName)

        Dim IdParameter As SqlParameter = New SqlParameter()
        IdParameter.Direction = ParameterDirection.InputOutput
        IdParameter.SqlDbType = SqlDbType.Int
        IdParameter.Value = -1
        IdParameter.ParameterName = "@BatchID"
        cmd.Parameters.Add(IdParameter)

        cnSQL.Open()
        cmd.ExecuteNonQuery()

When debugging the code, BatchName definitely has a value, and checking the parameters collection of cmd right before executing the urey shows 2 params, both named and with values set exactly as expected. I must have written code like this a thousand times - am I missing something here??

A: 

Ok appears that I forgot the line cmd.CommandType = CommandType.StoredProcedure. Adding this in made it work.

Macros