Click here to Skip to main content
15,896,154 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I tried to store my textbox value as byte in database, i wrote method to convert as byte & did it like this
C#
dpc.AddParameter(new DataParam("@Template_Content", fr.GetBytes(txtTemplatebody), DataParam.DataParamTypes.VarBinary, -1, 8000));

it works gud. but when i retrive data and bind it in grid i need to convert byte in particular column as string, i wasted lots of time in it. but i couldn't do it. please do help me. Thanks in advance.
Posted
Updated 15-Dec-14 21:20pm
v2
Comments
DamithSL 16-Dec-14 3:26am    
how you read data? update the question with your code

1 solution

For converting from string to bytes array and from bytes array to string you should use pair methods, that are using the same encoding, like in the next examples:

1.From string to byte array:
C#
byte[] resultArray = System.Text.Encoding.UTF8.GetBytes(stringValue);

2.From byte array to string:
C#
string stringResult = System.Text.Encoding.UTF8.GetString(byteArray);
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900