I have string value key:
TxtProductKey.Text has value "key"
Encode this value
byte[] Key = Encoding.ASCII.GetBytes(TxtProductKey.Text.Trim());
Save it in database table in a column of datatype binary(50) null.
The value in the table looks like this:
0x6B00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
Now I am trying to get it back in string value that I entered is Key
byte [] TempKey = (byte[])LicenseInfo.Tables[0].Rows[0]["ProductKey"];
var newText = Encoding.ASCII.GetString(TempKey);
but the result I am getting in newText is:
k\0\0\0\0\0\00\
Where am I doing something wrong? I hope for your suggestions
C# code for saving value in database:
Sqlconnection.Open();
SqlCommand Cmd = new SqlCommand("SpAddAttempts", Sqlconnection);
Cmd.CommandType = CommandType.StoredProcedure;
Cmd.Parameters.Add("@Attempts", SqlDbType.Int).Value = Attempt;
Cmd.Parameters.Add("@Activate", SqlDbType.Bit).Value = Activate;
Cmd.Parameters.Add("@Key", SqlDbType.Binary).Value = Key;
Cmd.ExecuteNonQuery();
CloseConnection();
Stored procedure is:
ALTER PROCEDURE [dbo].[SpAddAttempts]
@Attempts INT,
@Activate BIT,
@Key BINARY
AS
BEGIN
UPDATE License
SET Attempts = @Attempts,
Activate = @Activate,
ProductKey = @Key
WHERE LicenseId = '1'
END
0x6B657900...)