Click here to Skip to main content
15,896,606 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Please guide me how to retrieve image stored in sql database in asp.net using vb language here is my code.
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
       Try
           Dim strQuery As String = "select FName,LName,[Add],City,Image,Adddate from prakashkaur.dbo.PersonDetail "
           Dim cmd As SqlCommand = New SqlCommand(strQuery)

           Dim dt As New DataTable
           Dim adap As New SqlDataAdapter
           cmd.CommandType = CommandType.Text
           cmd.Connection = myConnection
           adap.SelectCommand = cmd
           adap.Fill(dt)

           Dim strQuery2 As String = "select FName,LName,[Add],City,Image,Adddate from prakashkaur.dbo.PersonDetail where 1=2"
           Dim cmd2 As SqlCommand = New SqlCommand(strQuery2)

           Dim dt2 As New DataTable
           cmd2.CommandType = CommandType.Text
           cmd2.Connection = myConnection
           adap.SelectCommand = cmd2
           adap.Fill(dt2)
           GridView1.DataSource = dt2


           If dt IsNot Nothing Then
               Dim inti As Integer
               For inti = 0 To dt.Rows.Count - 1
                   Dim bytes() As Byte = CType(dt.Rows(inti)("Image"), Byte())
                   Response.Buffer = True
                   Response.Charset = ""
                   Response.Cache.SetCacheability(HttpCacheability.NoCache)

                   Response.BinaryWrite(bytes)
                   dt2.ImportRow(dt.Rows(inti))
               Next



           End If


       Catch ex As Exception
           MsgBox(ex.Message)

       End Try
   End Sub
Posted
Updated 14-Apr-12 2:32am
v2
Comments
Abhinav S 14-Apr-12 8:32am    
Code tags added.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900