Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium


How to retrieve a .jpg file from a SQL database and save it to a file locally

Posted on 2005-03-03
Medium Priority
Last Modified: 2010-04-23
I need to retrieve a .jpg file from a SQL database and save it to a file locally  How do I do it using VB.Net?
Question by:RMAHelpDesk
LVL 19

Accepted Solution

arif_eqbal earned 2000 total points
ID: 13456222
try this...

        Dim cn As New SQLConnection(ConStr) 'Your Connection
        Dim Cmd As New SQLCommand("SELECT ID,MyImage FROM MyTable", cn) 'Change Table and field names

        Dim DA As New SQLDataAdapter(Cmd)
        Dim DT As New DataTable("MyTable")

        Catch ex As Exception
        End Try

        Dim i As Integer = DT.Rows.Count
        If i > 0 Then
            Dim BTImage() As Byte = DT.Rows(0)("MyImage")
            Dim MSImage As New MemoryStream(BTImage)
           Image.FromStream(MSImage).Save("C:\YOUR PATH", Drawing.Imaging.ImageFormat.Jpeg)
'Give Path and Format
        End If

I had this code running for Oledb I just changed the OleDB to SQL, hopefully it should work....

Author Comment

ID: 13460046
It worked!
I did have to add       Imports System.IO

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Whether it be Exchange Server Crash Issues, Dirty Shutdown Errors or Failed to mount error, Stellar Phoenix Mailbox Exchange Recovery has always got your back. With the help of its easy to understand user interface and 3 simple steps recovery proced…

577 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question