Board index » delphi » Using parameters with an update query

Using parameters with an update query

Hello,
  I would like to know how to use the following syntax with the TDBImages
component...

    Query1.Close;
    Query1.Params[0]... := DBImages...;
    Query1.ExecSQL;

What I'm wanting to do is store a bitmap image that is on my harddrive to
the database in a table field.  I'm familiar with doing this with text,
numbers, and dates.  However doing this with an image is very new to me.  I
would greatly appreciate any help anyone could give me...
Thanks,
Tony

 

Re:Using parameters with an update query


You could use SetBlobData which is a general purpose routine for transferring
data from a memory buffer to a parameter.

var
  ImageSize : Integer;
  MyBuffer : Array [1..100] of Byte;

Query1.Params [0].SetBlobData (@MyBuffer,ImageSize);

or

var
  BlobSize : Integer;
  MyPtr : Pointer;

GetMem (MyPtr,BlobSize);
...
Query1.Params [0].SetBlobData (MyPtr,BlobSize);
...
FreeMem (MyPtr,BlobSize);

A second method would be to load from a stream.

var
  MyStream : TMemoryStream;

Query1.Params [0].LoadFromStream (MyStream,ftGraphic);

or

Query1.Params [0].LoadFromStream (MyStream,ftBlob);

To load from disk:

var
  FileName : String;

Query1.Params [0].LoadFromFile (FileName,ftGraphic);

Quote
"Tony C. Wang" wrote:
> Hello,
>   I would like to know how to use the following syntax with the TDBImages
> component...

>     Query1.Close;
>     Query1.Params[0]... := DBImages...;
>     Query1.ExecSQL;

> What I'm wanting to do is store a bitmap image that is on my harddrive to
> the database in a table field.  I'm familiar with doing this with text,
> numbers, and dates.  However doing this with an image is very new to me.  I
> would greatly appreciate any help anyone could give me...

> Thanks,
> Tony

Other Threads