title: c# put a byte[] into an database and retrive later
body: <p>In my c# wpf project I have a byte array which needs to be stored in a database and converted back to a bytearray. What is the right approach for storing byte arrays? My query looks like:</p>
  
  <pre><code>string query = "UPDATE sometable SET file= @File  WHERE identifier =   @identifierwhere";
  
  upsert = new SqlCommand(query, _connector.getMsConnection());
  upsert.Parameters.Add(new SqlParameter("@identifier", v.UniqueIdentifier));
  upsert.Parameters.Add(new SqlParameter("@File  ", filestring""));
  
  filestring i made like:
  
  if (v.File != null)
  {
      fileString = GetStringFromBytes(v.File);
  }
  </code></pre>
  
  <p>I use this function</p>
  
  <pre><code>static string GetStringFromBytes(byte[] bytes)
  {
      char[] chars = new char[bytes.Length / sizeof(char)];
      System.Buffer.BlockCopy(bytes, 0, chars, 0, bytes.Length);
      return new string(chars);
  }
  </code></pre>
  
  <p>When i look in my database all i see is one letter 'A' when debbuging i see the value of filestring containse 'chinese?' characters. 
  What is the right way to store and retrive a byte array?</p>