Sql binary to c# - How to get SQL binary equivalent of binary in c#

后端 未结 2 622
野趣味
野趣味 2021-01-24 10:50

It might seem a dumb question to you guys. I have one SQL table with one binary column. It has some data in binary format.

e.g. 0x9A8B9D9A002020202020202020202020<

2条回答
  •  囚心锁ツ
    2021-01-24 11:42

    It really depends on which encoding was used when you originally converted from string to binary:

     byte[] binaryString = (byte[])reader[1];
    
     // if the original encoding was ASCII
     string x = Encoding.ASCII.GetString(binaryString);
    
     // if the original encoding was UTF-8
     string y = Encoding.UTF8.GetString(binaryString);
    
     // if the original encoding was UTF-16
     string z = Encoding.Unicode.GetString(binaryString);
    
     // etc
    

提交回复
热议问题