Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Images to a ??.jpeg

Status
Not open for further replies.

shmo

IS-IT--Management
Nov 25, 2002
18
US
Let say I have a table with images. How can I export them to a folder c:\images using the {primary key}as the name with the extension .jpg

ex.

id image
1 010101
2 010101
3 010101

as

1.jpg
2.jpg
3.jpg

 
is the image already in JPG format?
You can do it with some VB code using ADODB pretty easy.

just open a file for write,
read a line and use .GetChunk() method of the recordset to get a byte array and dump it to disk.
 
It is a jpeg.

Can post a sample vb code to do this? I never tried to write vb yet but it is time now!

Thanks!

 
Dim conn As ADODB.Connection
Dim rs As ADODB.Recordset

Set conn = New ADODB.Connection
Set rs = New ADODB.Recordset

'replace DatabaseName with your database name and ServerName with, guess what, your SQL Server name

conn.ConnectionString = "Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=DatabaseName;Data Source=ServerName"

conn.Open

rs.Open "SELECT ID, Image FROM BLAH", conn

Dim aByte() As Byte
Dim iFile As Integer
Do Until rs.EOF
ReDim aByte(rs.Fields("Image").ActualSize)
aByte = rs.Fields("Image").GetChunk(rs.Fields("Image").ActualSize)
iFile = FreeFile()
Open "C:\images\" & rs.Fields("ID").Value & ".JPEG" For Binary As #iFile
Put #iFile, , aByte
Close #iFile
rs.MoveNext
Loop

 
You rule, aussie! Thank you very much!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top