title: Write Image to SQL Server using Blob Literal String in C#
body: <p>I have a c# function that needs to write to a SQL image column.  I have the image in a byte array. The standard seems to be the use of SqlCommand while passing the byte array as a parameter of type System.Data.SqlDbType.Image.</p>
  
  <p>Unfotunately, my function can only use text queries (don't ask why) so I have to find a way to use T-SQL commands only.  What I have so far can write to the column but I don't know what format of string to make the image blob string.</p>
  
  <pre><code>sql = "DECLARE @ptrval binary(16)" +
  "SELECT @ptrval = textptr(Photo) FROM EMPhoto WHERE Employee='" + employeeID + "'" +
  "WRITETEXT EMPhoto.Photo @ptrval " + imageByteArrayAsString;
  </code></pre>
  
  <p>I've tried converting imageByteArray to a Hex string and Binary string but it doesn't seem to end up correct in SQL or in the application that reads it.</p>