Failed to convert parameter value from a SqlParameter to a String.

hi

i m using a stroed procedure and my and that strod prcedure is updating 3 tables

i m passing 9 parameters to that procedure. when i set all parameters in my coding work of vb.net and call executenonquery it gives me following error

"Failed to convert parameter value from a SqlParameter to a String."

code is as folllows...please help mee in this regard

strRowCount = CInt(strRowCount) + CInt("1")

cmd = dbComely.GetStoredProcCommand("sp_UpdateAndInsertStock ")

strStockTakingId.ParameterName = "@strTakingID"

strStockTakingId.SqlDbType = SqlDbType.VarChar

strStockTakingId.Direction = ParameterDirection.Input

strStockTakingId.Value = Me.txtStockTakingId.Text.Trim()

cmd.Parameters.Add(strStockTakingId)

strRowCnt.ParameterName = "@strRowCount"

strRowCnt.SqlDbType = SqlDbType.VarChar

strRowCnt.Direction = ParameterDirection.Input

strRowCnt.Value = strRowCnt

cmd.Parameters.Add(strRowCnt)

' Me.strRowCnt.Direction = ParameterDirection.Input

'cmd.Parameters.Add("@strRowCount", SqlDbType.VarChar)

strBranchID.ParameterName = "@strBranchID"

strBranchID.SqlDbType = SqlDbType.VarChar

strBranchID.Direction = ParameterDirection.Input

strBranchID.Value = Me.txtBranchId.Text.Trim()

cmd.Parameters.Add(strBranchID)

'cmd.Parameters.Add("@strBranchID", SqlDbType.VarChar)

'Me.dtDate.Value = Me.dtpickTransferDate.Value

'Me.dtDate.ParameterName = "@dtDate"

'' Me.dtDate.Direction = ParameterDirection.Input

'cmd.Parameters.Add(Me.dtDate)

strShoeStyleID.ParameterName = "@strStyleId"

strShoeStyleID.SqlDbType = SqlDbType.VarChar

strShoeStyleID.Direction = ParameterDirection.Input

strShoeStyleID.Value = strStyleId

cmd.Parameters.Add(strShoeStyleID)

'cmd.Parameters.Add("@strStyleId", SqlDbType.VarChar)

strColorCodeP.ParameterName = "@strcolorCode"

strColorCodeP.SqlDbType = SqlDbType.VarChar

strColorCodeP.Direction = ParameterDirection.Input

strColorCodeP.Value = strColorCode

'cmd.Parameters.Add("@strcolorCode", SqlDbType.VarChar)

cmd.Parameters.Add(strColorCodeP)

intShoeSizeP.ParameterName = "@intSize"

intShoeSizeP.SqlDbType = SqlDbType.Int

intShoeSizeP.Direction = ParameterDirection.Input

intShoeSizeP.Value = intShoeSize

cmd.Parameters.Add(intShoeSizeP)

'cmd.Parameters.Add("@intSize", SqlDbType.Int)

intShoeQtyP.ParameterName = "@intUserQty"

intShoeQtyP.SqlDbType = SqlDbType.Int

intShoeQtyP.Direction = ParameterDirection.Input

intShoeQtyP.Value = intShoeQty

'cmd.Parameters.Add("@intUserQty", SqlDbType.Int)

cmd.Parameters.Add(intShoeQtyP)

'Me.intRecStatus.Value = i

'Me.intRecStatus.ParameterName = "@intRecStatus"

'cmd.Parameters.Add(Me.intRecStatus)

intUserId.ParameterName = "@intUserId"

intUserId.SqlDbType = SqlDbType.Int

intUserId.Direction = ParameterDirection.Input

intUserId.Value = My.Settings.UserId

'cmd.Parameters.Add("@intUserId", SqlDbType.Int)

cmd.Parameters.Add(intUserId)

dtLastMDate.ParameterName = "@dtMDate"

dtLastMDate.SqlDbType = SqlDbType.DateTime

dtLastMDate.Direction = ParameterDirection.Input

dtLastMDate.Value = Date.Now

'cmd.Parameters.Add("@dtMDate", SqlDbType.DateTime)

cmd.Parameters.Add(dtLastMDate)

dbComely.ExecuteNonQuery(cmd, trns) < here trns is transactions




Answer this question

Failed to convert parameter value from a SqlParameter to a String.

  • Tom De Cort

    yes exacly

    thanx that was the problem and it is solved



  • nabeelfarid

    Your code:

    strRowCnt.ParameterName = "@strRowCount"
    strRowCnt.SqlDbType = SqlDbType.VarChar
    strRowCnt.Direction = ParameterDirection.Input
    strRowCnt.Value = strRowCnt

    has an error on the bold line: you there assing the parameter as the value of the same parameter. I think you made a typo there :)


  • Failed to convert parameter value from a SqlParameter to a String.