SQL image data type to jpeg

  • Does anyone have a way that I can convert an image data type from a SQL 2000 database into a jpeg file?

  • not natively in SQL server; there's no implicit conversion funcitons in SQL for images.

    you have to farm it out to a .NET object for example, convert it, and then put it back.

    Lowell


    --help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!

  • I don't need it in the database afterwards so that is fine.

  • in that case, here's an example from vb6: create a form, slap a button on it, and have the button call this function.change the SQL statement to your table, and the path information to where you want the images stored.

    I'm assuming you have both the filename and the image field in the same table:

    Private Function ExportBlobs()

        Dim ConnObj As Object

        Dim rsObj As Object

        Dim binObj As Object

        Dim SavePath As String

        Dim SQL As String

        On Error GoTo ExportBlobs_Error

       

        Set ConnObj = CreateObject("ADODB.Connection")

        Set rsObj = CreateObject("ADODB.Recordset")

        Set binObj = CreateObject("ADODB.Stream")

        ConnObj.ConnectionString = "Provider=SQLOLEDB;Persist Security Info=True;User ID=sa;Password=yourpass;Initial Catalog=webpictures;Network Library=dbmssocn; Data Source=myserver;"

        ConnObj.CursorLocation = adUseClient

        ConnObj.Open

       

        SQL = "SELECT PICTURENAME,PICTUREDATA FROM HDSPICTURES"

        SavePath = "C:\"

        Set rsObj = glbcn.Execute(SQL)

        Do While Not rsObj.eof

            Set binObj = CreateObject("ADODB.Stream")

            binObj.Type = adTypeBinary

            binObj.Open

            binObj.Write rsObj!PICTUREDATA

            binObj.SaveToFile SavePath & "\" & rsObj!PICTURENAME, adSaveCreateOverWrite

            binObj.Close

            Set binObj = Nothing

            rsObj.MoveNext

        Loop

        On Error GoTo 0

        Exit Function

       

    ExportBlobs_Error:

       

        MsgBox "Error " & Err.Number & " (" & Err.Description & ") in procedure ExportBlobs of Form frmTest"

    End Function

    Lowell


    --help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!

  • Cheers for that. It is a big help.

Viewing 5 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic. Login to reply