Visit our Sponsor   Visit our Sponsor
delphi3000.com - the free delphi knowledge platform
delphi3000.com - the free delphi knowledge platform
500 Users Online NOW
Have a look at your member-status

connecting people's knowledge


  - Recent ArticlesRSS feed for Recent Articles on delphi3000.com
  - List of All Articles
  - Top Viewed Articles
  - Articles (+Attachem.)
  - Articles Of Interest
  - Categories
  - Top Uploader
  - Search
  - Index

  - My Home
  - Submit an Article
  - My Articles
  - My Personal Data
  - My Bookmarks
  - Activities
  - Login/Logout

  - Sign Up
  - Why Sign Up
  - Newsletter

  - Press
  - Advertise

  - Contact
  - Feedback





Community
Borland
ClubeDelphi
Dr. Bob
UK-BUG
Delphi Meetings
Planeta Delphi



Loremo - the 1.5 liter car coming in 2009




Startblatt.de






Share this article with friendsShare this article with friends
Rate this articleRate this article - to keep the quality of delphi3000.com !
Comment this article or read through previous comments (3)


to save file in BLOB and read from BLOBGo to Mike Shkolnik's websiteFormat this article printer-friendly!Bookmark function is only available for registered users!
Product:
Delphi all versions
Category:
DB-General
Skill Level:
Scoring:
Last Update:
06/27/2002
Search Keys:
delphi delphi3000 article borland vcl code-snippet BLOB MEMO database save reastore load read file stream blobstream
Times Scored:
7
Visits:
10810
Uploader: Mike Shkolnik
Company: Scalabium Software
Reference: http://www.scalabium.com/faq/dct0141.htm
 
Question/Problem/Abstract:
How to save some file in BLOB-field and use it later
Answer:



If you develop a database related software, then very popular task is to
save some files (documents/images/reports/etc) in some BLOB field of table
and use these saved data later.

In this tip I want to show how this task could be solved.

To save a file to BLOB:
blob := yourDataset.CreateBlobStream(yourDataset.FieldByName('YOUR_BLOB'),
bmWrite);
try
  blob.Seek(0, soFromBeginning);

  fs := TFileStream.Create('c:\your_name.doc', fmOpenRead or
fmShareDenyWrite);
  try
    blob.CopyFrom(fs, fs.Size)
  finally
    fs.Free
  end;
finally
  blob.Free
end;

To load from BLOB:
blob := yourDataset.CreateBlobStream(yourDataset.FieldByName('YOUR_BLOB'),
bmRead);
try
  blob.Seek(0, soFromBeginning);

  with TFileStream.Create('c:\your_name.doc', fmCreate) do
    try
      CopyFrom(blob, blob.Size)
    finally
      Free
    end;
finally
  blob.Free
end;

Using this code you can work with any database engine (BDE/ADO/DAO/ODBC/etc)
and any file format (document of MS Word, spreadsheet of MS Excel, bitmap or
jpeg pictures, wav-files etc)

With best regards, Mike Shkolnik
E-Mail: mshkolnik@scalabium.com
WEB: http://www.scalabium.com





Please rate this article!
Skill level:
BeginnerExpert

Useful:
No!Very!

Overall rating:
PoorExcellent



Comments to this article
Write a new comment
a problem with Oracle
    mohammad norouzee (Sep 16 2004 5:26PM)

when I use it with Oracle database always receive the error "data type not supported" how can I use Oracle Blobs.
plz help me.

best regards
Respond

RE: a problem with Oracle
Mike Shkolnik (Sep 16 2004 7:28PM)

What database engine you use? BDE? ADO? DOA?...
How did you define the field in Oracle? BLOB/CLOB/LONG...
Respond

a problem
    mohammad (Sep 16 2004 5:19PM)

when I use it with Oracle database always I receive the error "Data Type not supported" can you help me. what I am to do?

I need it so much.

best regards

Respond














 
Sign up to consume product discounts for Bronze memberships !

read more


  Visit our Sponsor

 

  Community Ad of
E. Irigoyen
 
   














 







     
  Copyright © 2000 - 2007 delphi3000.com - All rights reserved. Terms of use. || Privacy
delphi3000.com is a service by bluestep.com IT-Services GmbH (Vienna)