How to Store a Bitmap Images into MSSQL field from Delphi

Hi,

I am using Delphi 7 with MS-SQL 2000 database. I want to use BDE or ADO connection to store a bitmap into a database field. My bitmap file size is usually 200kb.

I created a field as IMAGE type in database. and I used the following to insert my bitmap into it:

query1bitmapfield.LoadFromFile('myfile.bmp');
//query1bitmapfield is a TBlobField

The previous works fine with bitmaps smaller that 32kb size.

Is there any solution to store my 200kb images into a database field? and how to do this?
what field type is suggested to be used?

Regards,
Hamid Hossain
HamidHossainAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Imthiyaz_phCommented:
By default, the Blob size for BDE is limited to 32K. You can increase the limit upto 999K thru BDE Administrator:
 - Open BDE Administrator
 - Under Configuration tab, select Configuration -> Drivers -> Native -> MSSQL from the treeview.
 - Change the Blob Size to 999 and apply the changes (Ctrl + A)

You also need to change the Blob Size for each existing aliases that has been defined with MSSQL.

Unlike BDE, I havnt come up with any Blob size limitations with ADO. I have saved images more than 1MB into the DB using ADO.


The 'Image' datatype should be used for storing images into a table.

0
HamidHossainAuthor Commented:
Hi,

I tried using ADO but I still have the problem.

Tell me more about it or show me some code

Regards,
Hamid
0
geobulCommented:
Hi,

First try to explicitly typecast the field as blob or graphic field:

TBlobField(query1bitmapfield).LoadFromFile('myfile.bmp');
TGraphicField(query1bitmapfield).LoadFromFile('myfile.bmp');

Or use streams:

var
  fs: TFileStream;
begin
  fs := TFileStream.Create('myfile.bmp', fmOpenRead);
  try
    query1.Append; // or query1.Edit; for replacing the current record
    fs.Position := 0;
    TGraphicField(query1.FieldByName('bitmapfield')).LoadFromStream(fs);
    query1.Post;
  finally
    fs.Free;
  end;
end;

Regards, Geo
0
Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

Imthiyaz_phCommented:
I just tried it with AdoQuery:

    ADOQuery1.Append;
    ADOQuery1Logo.LoadFromFile(OpenDialog1.FileName);
    ADOQuery1.Post;

ADOQuery1Logo is of TBlobField type in Delphi and Image type in SQL.

Have u tried updating MDAC (Microsoft Data Access Components) ?
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
geobulCommented:
Using ADO the following works here:

uses dbtables;

// saving to DB
procedure TForm1.Button1Click(Sender: TObject);
var
  fs: TFileStream;
begin
  fs := TFileStream.Create('c:\room.bmp', fmOpenRead);
  try
    ADOTable1.Append; // or query1.Edit; for replacing the current record
    fs.Position := 0;
    TBlobField(ADOTable1.FieldByName('pic')).LoadFromStream(fs);
    ADOTable1.Post;
  finally
    fs.Free;
  end;
end;

// loading from DB to an Image
procedure TForm1.Button2Click(Sender: TObject);
var
  bs: TBlobStream;
begin
  bs := TBlobStream(ADOTable1.CreateBlobStream(ADOTable1.FieldByName('pic'), bmRead));
  try
    bs.Position := 0;
    Image1.Picture.Bitmap.LoadFromStream(bs);
  finally
    bs.Free;
  end;
end;

Regards, Geo
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Fonts Typography

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.