Passing string value(vb.net) to varbinary parameter in StoredProcedure

sureshcd10

Well-known member
Joined
Dec 25, 2003
Messages
77
I want to pass value in txtPassword.Text to to @Pwd varBinary(50) in SqlServer200 variable in a stored procedure.

Vb.net code I am using is as follows

Code:
 Resets the existing password with the new password
        Dim n As Integer
        sqlCmd = New SqlCommand("usp_SavePassword", conUserAccess)
        sqlCmd.CommandType = CommandType.StoredProcedure
        sqlCmd.Parameters.Add("@UserId", txtUserId.Text)
        sqlCmd.Parameters.Add("@Pwd", txtConfirmPassword.Text)
        If (txtConfirmPassword.Text = String.Empty) Then

        End If

        OpenConnection()
        sqlCmd.ExecuteNonQuery()
        ResetMessage()
        lblMessage.Text = "Your password has updated with the new password"

My stored procedure is as follows

Code:
CREATE PROCEDURE usp_SavePassword
(
 @UserId USERID,
 @Pwd varBinary(50)
)
 AS
set nocount on
begin
 
 update  IBUSER
 set  PASSWORDBIN = @Pwd
 where PKUSERID = @UserId 
 -- Error check
 if @@ERROR <> 0
  Return(-1)
 else
  Return
end

GO

I am getting the following error message

Implicit conversion from data type nvarchar to varbinary is not allowed. Use the CONVERT function to run this query.

How can I solve this problem ? Plzz help me
 
Dont pass a string...pass a binary value. The error is telling you what the exact problem is. Look up the CONVERT function in Sql Help.
 
Back
Top