Click here to Skip to main content
15,892,674 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi :) ,
I inserted images successfully in MS-access database using Fileupload server control, but i m unable to retrieve all images from database in datalist control which contain image and hyperlink server control in ItemTemplte and i used this select query.

"Select picture, name from gallery "

and i don't wana parametrized query, bcoz i wana show all images. :doh:

Thank's

Regards
Sutotpal :)
Posted

The code for retrieving images from MS-access is exactly the same as SQL-Server one.

All you need to do is change the data type inside the database to "Object OLE" and change any references inside your SQL Server code from "Image" (or varbinary(max) ), to also Object OLE.

Storing and Retrieving Images from SQL Server using Microsoft .NET[^]
 
Share this answer
 
Well, the article given to you by Sandeep does describe a way to do it. Thought, I'm unclear exactly what you're trying to do and you didn't say if you were using C# or VB. I can show you some code that I used to extract an image from the database, without writing anything to the disk...which the article given does:

VB
Public Function GetThumbnailFromDb(ByVal DataID As Long) As Image
        'check if the connectionString is already opened
        Dim wasOpen As Boolean = False
        If connectionString.State = ConnectionState.Open Then
            wasOpen = True
        Else
            connectionString.Open()
        End If

        'Create new dataset
        Dim DataDS As New DataSet
        Dim newDataAdapter As OleDbDataAdapter
        Dim sql As String = "SELECT Thumbnail, SizeMode FROM Data WHERE ID = " & DataID & ";"

        newDataAdapter = New OleDbDataAdapter(sql, connectionString)
        newDataAdapter.Fill(DataDS, "Data")
        newDataAdapter.Dispose()

        'if the connectionString wasn't open, close it
        If Not wasOpen Then
            connectionString.Close()
        End If

        'Convert the OleObject to an Image
        Dim result As Image = Nothing
        Dim temp() As Byte

        If Not IsDBNull(DataDS.Tables("Data").Rows(0).Item("Thumbnail")) Then
            temp = DataDS.Tables("Data").Rows(0).Item("Thumbnail")
            result = Image.FromStream(New MemoryStream(temp))
            result.Tag = DataDS.Tables("Data").Rows(0).Item("SizeMode")
        End If

        Return result
End Function


It uses the System.Data.OleDb library. This will extract the image into a form that you can use however you want. If you wanted to show all of the images, you would use your Select statement and just cycle through all of the rows and convert the data.

[Modified]
What in the world is the 1 vote and 2 vote for? Was the information I provided inaccurate?

No!

You tell me what he was asking and provide an answer. I was trying to help in what way I could. If you don't think it answers the question, but is still accurate, give it a 3.

What's with all the negativity!?
 
Share this answer
 
v5
Hi :)
Thank's for reply..

ya i took OLEObject datatype for image in ms-access.
i think.., u don't understand my question.

i wana show all images in using this query without passing any parameter like this.

"Select image from dbname"

and i used in GenricHndler file

Public Class pic_handler : Implements IHttpHandler
Public Sub ProcessRequest(ByVal context As HttpContext) Implements IHttpHandler.ProcessRequest
context.Response.ContentType = "image/gif"
Dim strm As Stream = ShowProductImage()
If strm Is Nothing Then
Exit Sub
End If
Dim buffer As Byte() = New Byte(4095) {}
Dim byteSeq As Integer = strm.Read(buffer, 0, 4096)
Do While byteSeq > 0
context.Response.OutputStream.Write(buffer, 0, byteSeq)
byteSeq = strm.Read(buffer, 0, 4096)
Loop
context.Response.BinaryWrite(buffer)
End Sub

Public Function ShowProductImage() As Stream
Dim StrSelect As String = "SELECT pic_Name,pic FROM images"
Dim cmd As OleDbCommand = New OleDbCommand(StrSelect, get_connetion)
' cmd.CommandType = CommandType.Text
' cmd.Parameters.AddWithValue("@ID";, ProImageId)
Dim img As Object = cmd.ExecuteScalar()
Try
Return New MemoryStream(CType(img, Byte()))
Catch
Return Nothing
Finally
conn.Close()
End Try
End Function


And on show.aspx.vb file, on PreRender_event

Sub GetSpecificVideo(ByRef dl_img As DataList)
Try
cmd = New OleDbCommand("SELECT pic_name,pic FROM images",get_connetion)
ole_adp = New OleDbDataAdapter()
ole_adp.SelectCommand = cmd
Dim ds As New DataSet
ole_adp.Fill(ds, "images")
dl_img.DataSource = ds.Tables(0)
dl_img.DataBind()
Catch ex As Exception
Throw New Exception(ex.ToString)
Finally
conn.Close()
End Try

And on show.aspx file

<ItemTemplate>
<asp:Image ID="Image1" ImageUrl='<%"pic_handler.ashx?"+Eval("Video_pic",{0})%>' runat="server"/>
</br>
<%#Eval("Video_name")%>
</ItemTemplate>

this is the summary

i could not finding my error..
Is it neccessary to pass parameter in genrichandler file?
if yes then
pls tell me

Thank's again :thumbsup:
 
Share this answer
 

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