Click to See Complete Forum and Search --> : ADO and Blob column
Chandarji
July 6th, 2001, 04:52 AM
My issue is about Oracle 8i and Visual Basic. I'm using ADO 2.5 and OLEDEB.
I want to store into the database ( BLOB column) the content of a Picture
File. How
can I do it?
Could you have a little pice of code to show hot to store and get this picture
to and from the database?
Can I save to the hard disk (of the client machine) the value of this BLOB
column?
Chandar
Cakkie
July 6th, 2001, 05:32 AM
You can find an example to do this with SQL server at the microsoft site. The thing you need to change to use it for oracle is thet part when establishing the connetion. But the AppendChunk and GetChunk methods work the same.
http://support.microsoft.com/support/kb/articles/q180/3/68.asp?FR=0
Tom Cannaerts
slisse@planetinternet.be
Programming today is a race between software engineers striving to build bigger and better idot-proof programs, and the universe trying to produce bigger and better idiots. So far, the universe is winning -- Rich Cook
Iouri
July 6th, 2001, 07:02 AM
Save picture to DB
Const MAX_PATH = 255
private Const CHUNK_SIZE = 1000
private Declare Function GetTempPath Lib "kernel32" _
Alias "GetTempPathA" (byval nBufferLength as Long, _byval lpBuffer as string) as Long
public Function SavePictureToDB(PictControl as Object, _
RS as Object, FieldName as string) as Boolean
'PURPOSE: SAVES PICTURE IN IMAGEBOX, PICTUREBOX, OR SIMILAR
'CONTROL to RECORDSET RS IN FIELD NAME FIELDNAME
'FIELD TYPE MUST BE binary (OLE OBJECT IN ACCESS)
'SAMPLE USAGE
'Dim sConn as string
'Dim oConn as new ADODB.Connection
'Dim oRs as new ADODB.Recordset''
'sConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\MyDb.MDB;Persist Security Info=false"'
'oConn.Open sConn
'oRs.Open "SELECT * FROM MYTABLE", oConn, adOpenKeyset, _
adLockOptimistic
'oRs.AddNew
'SavePictureToDB Picture1, oRs, "MYFIELD"
'oRs.Update
'oRs.Close
Iouri Boutchkine
iouri@hotsheet.com
Iouri
July 6th, 2001, 07:03 AM
Load from DB
public Function LoadPictureFromDB(PictControl as Object, _
RS as Object, FieldName as string) as Boolean
'PURPOSE: LOADS PICTURE, SAVED as binary DATA IN RECORDSET RS,
'FIELD FieldName to PICTUREBOX, IMAGEBOX (OR CONTROL'WITH SIMILAR INTERFACE)
'SAMPLE USAGE
'Dim sConn as string
'Dim oConn as new ADODB.Connection
'Dim oRs as new ADODB.Recordset'
''sConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\MyDb.MDB;Persist Security Info=false"'
'oConn.Open sConn'oRs.Open "SELECT * FROM MyTable", oConn, adOpenKeyset, adLockOptimistic
'LoadPictureFromDB Picture1, oRs, "MyFieldName"
'oRs.Close
Iouri Boutchkine
iouri@hotsheet.com
Chandarji
July 6th, 2001, 09:04 AM
Where is the definition of LoadPicturefromDB and SavePicturetoDB ?
tcleveland
January 24th, 2006, 04:09 PM
This simple Visual Basic form does two things saves a blob file and opens and displays the blob file. Regardless of what DB you are using retrieving and saving the "string data (the blob)" should not be an issue.
Start a VB project > Standard EXE
Add a RichText control to the form named RichText
Create two menu items Open (mnuOpen) and Save (mnuSave)
Copy and paste this code into the form.
Private Sub Form_Resize()
RichText.Move 0, 0, Me.ScaleWidth, Me.ScaleHeight
End Sub
Private Sub mnuOpen_Click()
Dim SourceFile As Long
Dim FileLength As Long
Dim StringData As String
SourceFile = FreeFile
Open "MyBLOB" For Binary Access Read As SourceFile
FileLength = LOF(SourceFile)
If FileLength = 0 Then
MsgBox "MyBLOB Empty or Not Found."
Else
StringData = String(FileLength, 0)
Get SourceFile, , StringData
RichText.TextRTF = StringData
End If
Close SourceFile
End Sub
Private Sub mnuSave_Click()
Dim FileNum As Long
Dim sRichText As String
FileNum = FreeFile
Open "MyBLOB" For Binary As FileNum
sRichText = RichText
Put FileNum, , sRichText
Close FileNum
MsgBox "BLOB Saved"
End Sub
Save the project!
Run the project
Open your favorite word processor. Type in some text using bold, underline, etc., insert a picture into the document.
Highligt the entire document content (Select All) and Copy.
Paste the information into the RichText control.
Click on Save menu item. The blob has been saved to file MyBLOB.
Exit and close the VB project.
Open the VB project.
Click the Open menu item. Whoala!
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.