Solved

Insert picture in Database

Posted on 2001-06-24
12
213 Views
Last Modified: 2010-04-06
1- How can I store the images in databases, I use Oralce, Blob datatype. when I call LoadFromFile a message "can not open file" appears. the SetBlobData and GetBlobData a message "unablecable operation" appears.

2- Does the ADO supports Blob datatypes?

if the answer works I will increase the points to 150 points
0
Comment
Question by:newbuilder
  • 4
  • 3
  • 2
  • +2
12 Comments
 
LVL 13

Accepted Solution

by:
Epsylon earned 150 total points
ID: 6222632
You can store for example jpeg images in the database by using a blob field (Ole Object field in Access):


var fs: TFileStream;
bs: TBlobStream;


Writing to database:

with Table1 do
begin
Append;
fs := TFileStream.Create('image1.jpg', fmOpenRead);
bs := TBlobStream(CreateBlobStream(FieldByName('picture'), bmWrite));
bs.CopyFrom(fs, 0);
bs.Free;
fs.Free;
Post;
end;


Reading from database:

with Table1 do
begin
fs := TFileStream.Create('image1.jpg', fmOpenWrite or fmCreate);
bs := TBlobStream(CreateBlobStream(FieldByName('picture'), bmRead));
fs.CopyFrom(bs, 0);
bs.Free;
fs.Free;
end;


If you want to display JPEG images you can use a TJPEGImage and then assign it to a TImage:


var j: TJPEGImage;

with Table1 do
begin
bs := TBlobStream(CreateBlobStream(FieldByName('picture'), bmRead));
j := TJPEGImage.Create;
j.LoadFromStream(bs);
Image1.Picture.Assign(j);
bs.Free;
j.Free;
end;


Hope this helps...

Epsylon.
0
 
LVL 22

Expert Comment

by:Mohammed Nasman
ID: 6222633
Hello

  you need to use stream to save and restore the image in Blob fields, I did this by using stream, but u can't do that with loadfromfile
   
  here's a good article to help you in that, using ADO with access database

Pictures inside a database
http://delphi.about.com/compute/delphi/library/weekly/aa030601a.htm

also I asked a question about that to store images in oracle database
http://www.experts-exchange.com/jsp/qManageQuestion.jsp?ta=delphi&qid=20121415

Best regards
Mohammed Nasman

0
 
LVL 13

Expert Comment

by:Epsylon
ID: 6222634
This also works for ADO...
0
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

 

Author Comment

by:newbuilder
ID: 6222651
Thank you Epsylon.

When I use TADOTable an error appear  "Data type not supported"
0
 
LVL 22

Expert Comment

by:Mohammed Nasman
ID: 6222660
newbuilder, I have this problem with oracle database when i use ado with blob field, it's work fine with me with access blob field using ado, I changed my program from ado to use BDE with oracle

0
 

Author Comment

by:newbuilder
ID: 6222668
so I did
0
 

Author Comment

by:newbuilder
ID: 6222802
mnasman
I have still some problems with the processing images in data base.
I feel the components is not stable. and I do not trust in BDE, so I went to the oracle database documentation, they solve the problem directly. I have oracle 8.0.6 the free version in oracle side. If you use Bfile (it likes blob) you can get the data from the disk and then convert and copy it to blob field.
Oracle documentation explains this method. In my opinion this method is the best. You will find the method in
\orant\doc\index.htm
0
 
LVL 4

Expert Comment

by:YodaMage
ID: 6224660
You are better off just storing the path to the image in a varchar field and adjusting the properties on which ever display component you are using at runtime. Storing images in the DB itself is a resource/performance disaster. JMHO
0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 6224755
didn't have any problem storing blob field via bde into an oracle-database
from 7.3 to 8.1.7 with epsylons provided code, up to blobs > 20MB

be sure you've the latest bde and the bugfixed sql-link

could be found at www.borland.com/devsupport/bde

meikl ;-)
0
 
LVL 22

Expert Comment

by:Mohammed Nasman
ID: 6225790
kretzschmar, BDE working fine with Oracle Blob field, but the problem with ADO and Oracle Blob field

0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 6226652
:-) ado is microsoft and will work properly with microsoft products, but may have problems with not microsoft products, as seen

i personell like to use doa from
http://www.allroundautomations.nl/doa.html
(comercial)
for work with oracle
(no ado or bde overhead and also no problems and faster than both)

meikl ;-)
0
 

Author Comment

by:newbuilder
ID: 6226904
Epsylon
I give you the points.
I found your code in the help. But I do not like the BDE.

Thank you for all
0

Featured Post

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Delphi 2010 Export to pdf 2 330
Strange behavior when a form is closed 6 56
select query - oracle 16 100
Find and Replace Stream with 0s 8 61
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

815 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now