I have problems getting my data type correct. I have a column in a database table that is Binary(64)
to hold the salted hash value of a password.
I don't understand how to present my data to SQL Server. I have read that I am supposed to pass the strSaltedPassword.GetHashCode()
as NVARCHAR(MAX)
but have not been able to make that work...
So next I tried having a parameter first of Binary
and then I have tried VarChar
This is my c# code and SQL insert query
//SqlDbType.VarChar = "Implicit conversion from data type varchar to binary is not allowed. Use the CONVERT function to run this query."
SqlParameter myField = sqlCmd.Parameters.Add("@myField", SqlDbType.VarChar);
myField.Value = strSaltedPassword.GetHashCode();
string sqlquery = "insert into Users ([UserName],[FirstName],[LastName],[EmailAddress],[EmailVerified],[VerifiedTimeStamp],[IsActive],[PasswordHash],[SecurityStamp],[AccountCreateTimeStamp]) values ('" + UserName.Text + "'" + ", '" + FirstName.Text + "'" + ", '" + LastName.Text + "'" + ", '" + Email.Text + "'" + ", 'false', getdate(), 'true', @myField, '" + strGetNewUserSalt + "', + getdate())";
sqlCmd.CommandText = sqlquery;
sqlConn.Open();
sqlCmd.ExecuteNonQuery();
I get this error:
"Implicit conversion from data type varchar to binary is not allowed. Use the CONVERT function to run this query"
Do I also need to Declare @myField as NVARCHAR (Max)
on the SQL side ??
I am a bit out of my element on this and could really use some help.