title: Store an image in a SQL Server CE database
body: <p>Does any one know of an example on how to store an image in a SQL Server CE database?</p>
  
  <p>What data type should the column be?  (I am guessing binary.)</p>
  
  <p>I use Linq-To-Datasets.  Is it possible using that to put the image into the database and pull it out again later?</p>
  
  <p>Thanks for any advice.</p>
  
  <hr>
  
  <p>Here is how I did it:</p>
  
  <pre><code>MemoryStream stream = new MemoryStream();
  myBitmapImage.Save(stream, ImageFormat.Png);
  myInsertLinqToDataSetRow.IMAGE_COLUMN = stream.ToArray();
  </code></pre>
  
  <p>To load it back out again I did this:</p>
  
  <pre><code>MemoryStream stream = new MemoryStream(myLinqToDataSetRow.IMAGE_COLUMN);
  myBitmapImage.SignatureImage = new Bitmap(stream);
  </code></pre>
  
  <p>I found a page on MSDN that said that the Image column type is going away and that you should use varbinary(MAX).  Max is not supported on SQL Server CE so I did varbinary(8000).</p>
  
  <p>LATER NOTE: while varbinary(max) is not supported on SQL Server CE.  Varbinary(8000) is not big enough for many images.  I did end up using the Image type even though it is planned to be deprecated.  Once ms offers a resonable alternitive on the mobile platform I will consider switching.</p>