Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert SQL Binary Data to String in C#

Tags:

c#

Does anybody have sample code to convert from binary data to string in c#?

like image 250
RPS Avatar asked Sep 03 '25 04:09

RPS


2 Answers

Sounds like you just need to decode the binary data. Therefore you need an encoding (like utf-8 or unicode).

Example:

var textFromBinary = System.Text.Encoding.UTF8.GetString(myBinaryData);
like image 83
Koen Avatar answered Sep 04 '25 19:09

Koen


If your binary data is stored in byte array and you want to convert it to Base64-encoding, you can use Convert.ToBase64String method:

var base64String = Convert.ToBase64String(yourBinaryDataHere);
like image 33
Anton Gogolev Avatar answered Sep 04 '25 17:09

Anton Gogolev