Rabu, 04 Februari 2009

MySQL and BLOBs - Retreiving Data



Ok, so now that our image is in the table, we need to get it back out. As we have covered them already, let's get the connection and recordset objects initialized right away:

Dim conn As New ADODB.Connection
conn.ConnectionString = GloConnectionString
conn.CursorLocation = adUseClient
conn.Open

Dim rs As New ADODB.Recordset
Dim mystream As New ADODB.Stream
mystream.Type = adTypeBinary

rs.Open "Select * from files WHERE files.file_id = 1", conn


We have opened a connection and a recordset and also declared our stream. To get our file back out, we open the stream, write to it from the recordset, and then save the data to a file, as follows:

mystream.Open
mystream.Write rs!File
mystream.SaveToFile "c:newimage.gif", adSaveCreateOverWrite

mystream.close
rs.Close
conn.Close


We load the binary data out of the recordset using the mystream.Write rs!file syntax, where rs!file is the field of the recordset that contains the binary data we will "write" to the stream. The SaveToFile method takes two arguments: the target location, and a variable that determines the stream's actions when a file exists. When adSaveCreateOverWrite is specified, existing files will be overwritten. When adSaveCreateNotExists is specified, files will not be overwritten if they exist.



source :http://www.devarticles.com

-------------------------------------------------------

Trik Gambar Bergerak

Trik Gambar-dimouse

Trik hapus pwd mysql

Trik insertin to db

Trik jadi root dilinux

Trik jam-distatus-bar

Trik Koneksi-ke database

Trik Koneksi-msql-php

Trik lihat-database-mysql

Trik membahas-fungsi-else

Trik member-area