If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > PC based Database Applications > Microsoft Excel > BLOB column file messes up

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 02-28-05, 16:27
bhavesh78 bhavesh78 is offline
Registered User
 
Join Date: Dec 2004
Posts: 78
Question BLOB column file messes up

I am using following code to retrieve a file from database from a BLOB column. I am able to retrieve the file and save in c:\temp directory, but VBA adds some junk characters at start of file making some files like jpg images un-readable. Can anyone tell whats wrong with the code or or do I need to use some other driver for connection etc...

Code:
Sub Test()
    Dim ProdConnectString
    Dim conn As New ADODB.Connection
    Dim rs As New ADODB.Recordset
    Dim myStreaM As New ADODB.Stream
    'String used for connecting to DB
    ProdConnectString = "provider=msdaora.1;user id=user;password=psd;data source = ds;option=1+2+8+32+2048+16384"
    Set conn = New ADODB.Connection
    conn.ConnectionString = ProdConnectString
    conn.CursorLocation = adUseClient
    conn.Open
    rs.Open "select file_data from TABLE where NAME ='ABCD.txt'", conn
    myStreaM.Open
    myStreaM.WriteText rs!file_data
    myStreaM.SaveToFile "c:\temp\XYZ.txt" , adSaveCreateOverWrite 
    myStreaM.Close
    rs.Close
    conn.Close
End Sub
File example (first 2 characters are junk, same characters are repeated in all files):
ÿþ1
2
3
4
5
6
7
8
9
10

Thanks.

~BS

Last edited by bhavesh78; 02-28-05 at 20:52.
Reply With Quote
  #2 (permalink)  
Old 03-01-05, 12:17
bhavesh78 bhavesh78 is offline
Registered User
 
Join Date: Dec 2004
Posts: 78
Smile

I found out the solution. Need to declare myStreaM as binary to work properly as data is coming from binary column.

Code:
        Dim myStreaM As New ADODB.Stream
        myStreaM.Type = adTypeBinary
~BS
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On