February 12, 2007 at 11:48 am
Does anyone have a way that I can convert an image data type from a SQL 2000 database into a jpeg file?
February 12, 2007 at 2:53 pm
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
February 13, 2007 at 5:31 am
I don't need it in the database afterwards so that is fine.
February 14, 2007 at 5:55 am
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
February 14, 2007 at 5:58 am
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