Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2552
  • Last Modified:

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
0
HamidHossain
Asked:
HamidHossain
1 Solution
 
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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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
 
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

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now