title: How to convert varBinary into image or video when retrieved from database in C#
body: <p>I am using visual studio 2010, (desktop application) and using LINQ to SQL to save image/video or audio files to database in dataType <code>VarBinary (MAX)</code>. This I can do... Problem is, I can't get them and display them in xaml because I can't get the converting part correct. Here is what I have so far (though its not working);</p>
  
  <pre><code>    private void bt_Click (object sender, RoutedEventArgs e)
      {
         databaseDataContext context = new databaseDataContext();
  
          var imageValue = from s in context.Images
                              where s.imageID == 2
                              select s.imageFile;
  
          value = imageValue.Single().ToString();        
          //convert to string and taking down to next method to get converted in image
      }
  
      public string value { get; set; }
  
  
      public object ImageSource //taking from http://stackoverflow.com/
      {
          get
          {
              BitmapImage image = new BitmapImage();
              try
              {
                  image.BeginInit();
                  image.CacheOption = BitmapCacheOption.OnLoad;
                  image.CreateOptions = BitmapCreateOptions.IgnoreImageCache;
                  image.UriSource = new Uri(value, UriKind.Absolute);
                  image.EndInit();
  
                  Grid.Children.Add(image);
              }
              catch { return DependencyProperty.UnsetValue; } return image;
          }
  
      } 
  </code></pre>
  
  <p>I not even sure if I am on the correct track? And I am assuming that video or audio is quite similar methods?</p>