Here is my code for single image retreivation.
''''
Expand|Select|Wrap|Line Numbers
- Partial Public Class dspimg
- Inherits System.Web.UI.Page
- Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
- Response.ContentType = "image/jpg"
- Using dbcon As New SqlConnection("Data Source=localhost\sqlexpress;Initial Catalog=Employee;Integrated Security=True;")
- Dim id As Integer
- Dim sqlCom As New SqlCommand
- Integer.TryParse(Request.QueryString("ID"), id)
- sqlCom.Connection = dbcon
- sqlCom.CommandType = CommandType.Text
- sqlCom.CommandText = "SELECT img FROM PIC" + "WHERE id=@ImageID"
- sqlCom.Parameters.Add("@ImageID", SqlDbType.Int).Value = id
- ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
- Try
- dbcon.Open()
- Dim imgContents As Byte() = DirectCast(sqlCom.ExecuteScalar(), Byte())
- 'Now that we have the image, writing it to the Response's Output Stream
- Response.BinaryWrite(imgContents)
- Catch ex As Exception
- MsgBox(ex.Message)
- 'Something went wrong connecting to the Database
- Finally
- 'Ensuring that the database connection is closed
- 'Even if something went wrong
- dbcon.Close()
- End Try
- End Using
- End Sub
Expand|Select|Wrap|Line Numbers
- USE [Employee]
- GO
- /****** Object: Table [dbo].[PIC] Script Date: 12/05/2011 03:29:09 ******/
- SET ANSI_NULLS ON
- GO
- SET QUOTED_IDENTIFIER ON
- GO
- CREATE TABLE [dbo].[PIC](
- [id] [numeric](18, 0) NULL,
- [img] [image] NULL
- ) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]