title: ASP.NET - Convert image data from SQL Server to image in listview
body: <p>I have a page to upload images to an image column in SQL Server and it converts it to binary... On another page I want to retrieve the images. I'm trying to do it like this in a listview:</p>
  
  <pre><code>&lt;ItemTemplate&gt;
      &lt;tr style=""&gt;
          &lt;td&gt;
              &lt;img src='data:image/jpg;base64,&lt;%# Eval("Image") %&gt;' /&gt;
          &lt;/td&gt;
          &lt;td&gt;
              &lt;asp:Label ID="ImageDescLabel" runat="server" Text='&lt;%# Eval("ImageDesc") %&gt;' /&gt;
          &lt;/td&gt;
      &lt;/tr&gt;
  &lt;/ItemTemplate&gt;
  </code></pre>
  
  <p>Am I doing something wrong? I figured it would be the best way to go about this.</p>
  
  <p>The Image save code looks like this:</p>
  
  <pre><code>    void InsertImage()
      {
          byte[] theFile = new byte[FileUpload1.PostedFile.ContentLength];
          HttpPostedFile file = FileUpload1.PostedFile;
          file.InputStream.Read(theFile, 0, (int)FileUpload1.PostedFile.ContentLength);
  
          if (FileUpload1.PostedFile != null &amp;&amp; FileUpload1.PostedFile.FileName != "")
          {
              int result = new _Image()
                  {
                      ImageName = txtFileName.Text,
                      ImageFile = theFile,
                      ImageDesc = txtDescription.Text
                  }.AddImage();
  
              txtFileName.Text = "";
              txtDescription.Text = "";
          }
      }
  </code></pre>