Skip to main content

Retrieve & display image from sql database in vb.net


In my previous post I have discuss about how to store image into sql server database using vb.net.
It is time to fetch image from sql server database and display into picture box. Here is the snapshot of vb.net code.
First of all we have to imports these namespace in our class.

Imports System.IO
Imports System.IO.Stream
Public Function getImagefromByte(ByVal data As Byte()) As Image
        Dim ms As MemoryStream = New MemoryStream()
        Dim img As Image
        Try
            ms.Write(data, 0, data.GetUpperBound(0))
            img = Image.FromStream(ms)
        Catch ex As Exception
            img = My.Resources.noimage
        Finally
            'ms.Close()
            'ms = Nothing
        End Try
        getImagefromByte = img
    End Function

Here is code that show how to call this function and display image into picture box. ds is object of DataSet class and DataAdaptor is used fill that dataset, ”photo” field type in sql database is image.
pic is PictureBox control.

        Dim data() As Byte
        data = CType(ds.Tables(0).Rows(0)("photo"), Byte())
        pic.Image = getImagefromByte(data)


this will fetch picture from sql database and display into  picture box.



Comments

  1. my search ends here for display image from sql server database to picture box.solved my problem.

    Thanks
    Rakesh

    ReplyDelete
  2. Hello, I want to fetch the picture from database, which I do kind of like you explain here, but then I don't have a picturebox, I only have a RichTextBox with html email Body.
    My picture is in memorystream from database and i want to replace the embedded pictures in the html with my new downloaded picture.
    Can you help?

    ReplyDelete

Post a Comment

Popular posts from this blog

Download SCERTUP BTC 2011 Application Form

Note : Professional Courses Student can also now apply for UP BTC 2011 and date extended. The SCERT of UP was established at Lucknow in 1981 as an apex government organization at the state level. The State Council of Educational  Research  &  Training , U.P., is providing academic support to the District Primary Education Program intended primarily to accelerate the processes of pedagogical renewal in the state.   The Utter Pradesh Education Board Basic Training Certificate or B.T.C Application Form 2011 is now available for download on the Uttar Pradesh State Council of Educational Research & Training (SCERT) official website. Pre-Service Training * Training of Special B.T.C. Trainees. Training Urdu Special B.T.C. in process * Training of Shiksha Mitras, EGS/ AIE Instructors & Literacy functionaries. * Pre-service Training for physical Education and nursery training also being conducted. The thrust areas include  (a) development of curriculum, r

UP TET 2011 Exam Application,UPTET 2011 Result | UPTET 2011 Revised Result

UPTET 2011 Result | UPTET 2011 Revised Result | UPTET 2011 Updated Result |Board of High School and Intermediate Education Uttar Pradesh, Allahabad UP TET Advertisement 2011 and Exam Detail/Admit Card/Call Letter Download UP TET 2011 FORM & DETAILS  GET LATEST DETAIL ABOUT 72825 Primary Teacher Merit List UP TET 2011 Application form submission last date is 18-Oct-2011.Forms will be distributed from PNB bank all over UP.According to latest news Appearing B.Ed student also eligible for TET exam 2011 so they can also submit their forms to concern District.There is no requirement for Rojgar Registration No and Bank receipt within the application form.UP TET 2011 exam results will be avail on http://www.uptet2011.com . Now you can easily get Application from from the P.N.B bank Branches. UPTET 2011 Result | UPTET 2011 Revised Result | UPTET 2011 Updated Result |  Board of High School and Intermediate Education Uttar Pradesh, Allahabad

ASP.Net : The test form is only available for methods with primitive types as parameters

I made a webservice but some methods cannot be tested, I get following message:   The test form is only available for methods with primitive types as parameters.    when click on the service it display this irritating message. I found that this could also be due to passing the variables in the Method definition as ref.  I removed in marked in red circle to solve the problem.