title: How do I retrieve an image from a database and show it in an image control?
body: <p>I have entered an image in sql server database successfully. Now i want to retrieve this image from database and show it in an Image control. I don't want to put any ListBoxes on the page. I wrote in ASP dot Net..</p>
  
  <pre><code>Dim MS As MemoryStream
  Dim IMG As System.Drawing.Image
  Dim FS As FileStream
  Dim FI As FileInfo
  Dim IMGSTRM As Stream
  Dim IMGBYTS As Byte()
  Dim ImgData() As Byte
  
      CMD1 = New SqlCommand("select * from IMG where userid=0", CON1)
      If Not IsNothing(RDR1) Then RDR1.Close()
      RDR1 = CMD1.ExecuteReader()
      If RDR1.Read Then
          IMGBYTS = RDR1!img
          MS = New MemoryStream(IMGBYTS, False)
          IMG = Image.FromStream(MS)
          PIC1.ImageUrl = IMG
      End If
  </code></pre>
  
  <p>The problem is in the bold 2 lines above End If</p>