How to save an image as binary ?

Discussion of open issues, suggestions and bugs regarding SDAC (SQL Server Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
haci
Posts: 11
Joined: Tue 17 Jan 2006 11:32

How to save an image as binary ?

Post by haci » Tue 24 Apr 2007 06:30

I would like to save an image as binary, i tried but it doesn't work! How can i do that ? Thank you.

Jackson
Posts: 512
Joined: Thu 26 Jan 2006 10:06

Post by Jackson » Tue 24 Apr 2007 08:51

You can use the following construction to insert an image in the table.

Code: Select all

...
var
  BlobField: TBlobField;
begin
  MSQuery1.Insert;
  BlobField := MSQuery1.FieldByName('Picture') as TBlobField;
 
  BlobField.LoadFromFile('D:\Image.bmp');
  MSQuery1.Post;
end;
In this example, the "Picture" field is has the IMAGE data type.

haci
Posts: 11
Joined: Tue 17 Jan 2006 11:32

Thank you...

Post by haci » Thu 26 Apr 2007 14:32

Thank you.

Wallygator
Posts: 1
Joined: Wed 08 Sep 2010 14:24

adding images to blobfield

Post by Wallygator » Wed 08 Sep 2010 14:30

This code works with the insert

Code: Select all

  
 MSQuery1.insert;
  BlobField := MSQuery1.FieldByName('Picture') as TBlobField;
  if getpic.Execute then
  BlobField.LoadFromFile(getpic.filename);
  MSQuery1.Post;
But what if i want to edit and exsisting record

Code: Select all

   MSQuery1.edit;
  BlobField := MSQuery1.FieldByName('Picture') as TBlobField;
  if getpic.Execute then
  BlobField.LoadFromFile(getpic.filename);
  MSQuery1.Post;
I get an EMSError "incorrect syntax near the keyword 'group'

WHY ???
Thanks

AndreyZ

Post by AndreyZ » Thu 09 Sep 2010 09:15

Hello,

I could not reproduce the problem. Please, specify the SQL code that you are using in the MSQuery1.SQL and MSQuery1.SQLUpdate properties, and the exact place of the error appearance.
Note that the text, ntext, and image data types cannot be compared or sorted, except when using IS NULL or LIKE operator.

Post Reply