Link to home
Start Free TrialLog in
Avatar of KPBecker
KPBecker

asked on

How to write a stream to a blob-field ?

Hi,

I want to write into and read from a a stream to a blob-field (Delphi 7, ADO-query, MS-Access).
Performing the ExecSQL (see below) an exception occurs:

"Das Feld ist zu klein für die Datenmenge, die Sie hinzufügen wollten."

(about: "The field is too small for the retrieved data ... ")

The parameter "pR" referres to a OLE-Object (MS-Access), this should be good for a blob.

Which field is too small ?  I want to write a small amount of data to a nearly bottomless blob !  Why that ?

Thanks,
K.-P. Becker



PS:
Thanks to esoftbg and Meikl K. for their help some days ago.
My "Thank-you-comment" got lost.
K.-P. Becker

-----------------------------------------------------------------------------------------------------------------

TResi = array[0..80, 0..3] of word;
.....
var
  Resi: TResi;
  stResi: TStream;
.....

    SQL.Clear; SQL.Add('insert into tab1  ( ..., Resi) values (..., :pR) ');

    stResi:= TMemoryStream.Create;
    stResi.Write(Resi[0,0], 81*4*SizeOf(Word));
    stResi.Seek(0, soFromBeginning);

    with  qryA.Parameters  do
    begin
      ....
       ParamByName('pR').LoadFromStream(stResi, ftBlob);
      qryA.ExecSQL;                                                                //  !!!!!
    end;



Avatar of KPBecker
KPBecker

ASKER

Possibly the translation of the error-message is:

"The field is too small to accept the amount of data you attempted to add"

K.-P. Becker

I changed the dim of the array Resi to array{0..10,0..3] of word (= 88 bytes)
and replaced TStream with TMemoryStream:

the same error came up !

K.-P. Becker
Very rough code rip

This is how I do the save

  var
    lBinStream : TMemoryStream;
lBitmap: TBitmap;
      li: integer;
begin
  lBitmap:=TBitmap.Create;
  lBinStream:=TMemoryStream.Create;
  lBitmap.LoadFromFile('SomeFile.bmp');
  lBitmap.SaveToStream(lBinStream);  

  adoMain.CommandText:='AddPic';
    adoMain.Parameters.Refresh;
    for li:=1 to adoMain.Parameters.Count-1 do
      if adoMain.Parameters[li].Direction<>pdInput then
        adoMain.Parameters[li].Direction:=pdOutput
  adocMain.Parameters[1].Value:=ID;
  adocMain.Parameters[2].LoadFromStream(lBinStream , ftVarBytes);
  adocMain.Execute;
end;


Load From database

GetPics
var
  lBinStream: TMemoryStream;
  lbitmap: TBitmap;
begin
lBitmap:=TBitmap.Create;      
Result:=false;
      try
    with adodsPic do
    begin
      Active:=false;
      parameters[1].Value:=ID;
      Active:=true;
      while not eof do
      begin
        lBinStream:=TMemoryStream.Create;
        TBlobField(FieldByName('Pic')).SaveToStream(lBinStream);
        lBinStream.Seek(0, soFromBeginning);
        lBitmap.LoadFromStream(lBinStream);
        lBitmap.SaveToFile(c:\pic1.bmp');
        FreeAndNil(lBinStream);
        Next;
      end;
    end;
    Result:=true;
      except
        on E:Exception do DoError(E);
      end;
end;


sorry this is a very quick code put together but it may help you out


regards
No comment has been added to this question in more than 21 days, so it is now classified as abandoned.
I will leave the following recommendation for this question in the Cleanup topic area:

Delete - Refund

Any objections should be posted here in the next 4 days. After that time, the question will be closed.

Jacco
EE Cleanup Volunteer
Sorry about the confusion. I am new to CleanUp volunteering. If the asker does not respond to a comment there can be no refund. So here is my new recommendation:

No comment has been added to this question in more than 21 days, so it is now classified as abandoned.
I will leave the following recommendation for this question in the Cleanup topic area:

Delete - No Refund

Any objections should be posted here in the next 4 days. After that time, the question will be closed.

Jacco
EE Cleanup Volunteer
The code I posted answers the question
Hi pcsentinel,

You might be right. While reading the question I thought you were only displaying the way you are used to reading/writing ADO blob fields. I assumed you did not necessarily find the cause of the error "Das Feld ist zu klein für die Datenmenge, die Sie hinzufügen wollten." occuring.

Regards Jacco
ASKER CERTIFIED SOLUTION
Avatar of pcsentinel
pcsentinel

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Hi, pcsenitel,

I tried your solution and it really works. Still I do not know whats wrong with my code bat I think that happens in programming.

Thanks,
K.-P. Becker