开发者

Parameter gets lost in query

开发者 https://www.devze.com 2022-12-17 06:09 出处:网络
Ok, I\'m stumped here - the following code throws an error Procedure or function \'importsp_CreateDiallerBatch\' expects parameter \'@BatchName, which was not supplied`

Ok, I'm stumped here - the following code throws an error

Procedure or function 'importsp_CreateDiallerBatch' expects parameter '@BatchName, which was not supplied`

Code:

        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 che开发者_C百科cking the parameters collection of cmd right before executing the query 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?


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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号