Additional
dbCAP
AnyDAC
ThinDAC
NCOCI8
Topic: How to insert and read BLOB field
How to insert and read BLOB field
Posted: 2007/04/03 21:38
 
Hi Dmitry

How do I insert (and later read) BLOB field?

I tried:

var
bs: TStream;

TDTable1.Open;
TDTable1.First;
TDTable1.Edit;
bs := TDTable1.CreateBlobStream(TDTable1.FieldByName('Memo1'), bmWrite);
Memo1.Lines.SaveToStream(bs);
bs.Free;
TDTable1.Post;
TDTable1.Close;

But it gives me error on Post... 'update command changed 0 records, but must update only single record'.

I don't want to save just text (Memo1.Lines), but graphic files as well.

I'm doing something wrong, I know.

Thanks.
Zoran

Post edited by: ZoranMilenovic, at: 2007/04/03 22:46
Re:How to insert and read BLOB field
Posted: 2007/04/04 14:19
 
Hi Dmitry

Never mind. I figured it out. If somebody is interested, here are details...

[for Memo]

SQL in TDQuery1:

   update Sys set Memo1=:mmo where Id=2


paramater 'mmo' is ftMemo data type


   TDQuery1.ParamByName('mmo').Value := Memo1.Lines.Text;   TDQuery1.ExecSQL;


[for images]

SQL in TDQuery2:

   update Sys set Graphic=:graphic where Id=2


paramater 'graphic' is ftBlob data type


   TDQuery2.ParamByName('graphic').LoadFromFile('D:\Images\Fun\Face.bmp'ftBlob);   TDQuery2.ExecSQL;


[to retrieve image]


   bsTStream;   fsTFileStream;   bs := TStream.Create;   bs := TDClientDataSet1.CreateBlobStream(TDClientDataSet1.FieldByName('Graphic'), bmRead);   bs.Position := 0;   fs := TFileStream.Create('D:\Face.bmp'fmCreate);   fs.CopyFrom(bsbs.Size);   fs.Free;   bs.Free;



Simple (when you know how )......

Zoran

Post edited by: Diman, at: 2007/04/04 22:32