Okay so i found what was wrong, it was in the sql convert function. I was converting to varchar(30) when it was supposed to be nvarchar(30). To see the difference. What is the difference between varchar and nvarchar?
I guess this might be a silly question but i can't seem to be able to remove some sort of space from a string returned by this function. I guess the first real question is why is this function returning a string like this "1 2 3 4 5 6 7 8 9" when we're saving to the database like this "1234789". Second question is why something like this
Replace("1 2 3 4 5 6 7 8 9","\p{Zs}","")
or
Replace("1 2 3 4 5 6 7 8 9"," ","")
Is not working, i have a feeling its because of the characters inbetween look like spaces but are not.
Private Shared Function GetEncryptedPmtField(lhID As Integer, accountId As Integer, fieldName As String)
Dim openKeyCmd = String.Format("OPEN SYMMETRIC KEY somekey DECRYPTION BY PASSWORD = '{0}'", ConfigurationManager.AppSettings("Somethingsomething"))
Const closeKeyCmd As String = "CLOSE SYMMETRIC KEY somekey"
Dim command As New SqlCommand()
command.Connection = New SqlConnection(ConfigurationManager.ConnectionStrings("Something").ConnectionString)
command.CommandType = CommandType.Text
command.CommandText = String.Format("{0} SELECT convert(varchar(30),decryptbykey({1}) FROM paymentacct WHERE lh_id = @lhid AND id = @id ; {2}", openKeyCmd, fieldName, closeKeyCmd)
command.Parameters.AddRange({New SqlParameter With {.ParameterName = "lhid", .Value = lhID}, New SqlParameter With {.ParameterName = "id", .Value = accountId}})
command.Connection.Open()
Dim baNum = command.ExecuteScalar().ToString()
command.Connection.Close()
Return baNum
End Function