0

Hello,
I used the below coding to store an image into the database.

lblImagePath.Text = ImageUpload.PostedFile.FileName
        ImageUpload.PostedFile.SaveAs(lblImagePath.Text)
        Dim mbytes() As Byte = System.IO.File.ReadAllBytes(lblImagePath.Text)
        Dim cn As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|\database\db.mdb;Persist Security Info=False")
        Dim cmd As New OleDbCommand("insert into ImageTable values (@Image)", cn)
        cmd.Parameters.Add("@Image", OleDbType.Binary, mbytes.Length).Value = mbytes
        cn.Open()
        cmd.ExecuteNonQuery()
        Response.Write("Image load Success")
        cn.Close()

Now how to load this image into an image box?

3
Contributors
3
Replies
4
Views
7 Years
Discussion Span
Last Post by sakhi kul
0
Protected Sub imgUpload_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles imgUpload.Load
        Dim cmd As New OleDbCommand("select ImageData from ImageTable where ImageName='menu.JPG'", DataConn)
        DataConn.Open()
        Dim dr As OleDbDataReader
        cmd.ExecuteNonQuery()
        dr = cmd.ExecuteReader
        dr.Read()
        Response.BinaryWrite(dr("ImageData"))
        dr.Close()
    End Sub

I used the above and the image in displayed in imagebox, but in the page i am getting the as string as below.

Attachments image_error.JPG 87.95 KB
0

if your image size is larger or you want to display more images then use generic handler, pass Image id to it.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.