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').LoadFrom Stream(stR esi, ftBlob);
qryA.ExecSQL; // !!!!!
end;
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').LoadFrom
qryA.ExecSQL; // !!!!!
end;
ASKER
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
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('Some File.bmp') ;
lBitmap.SaveToStream(lBinS tream);
adoMain.CommandText:='AddP ic';
adoMain.Parameters.Refresh ;
for li:=1 to adoMain.Parameters.Count-1 do
if adoMain.Parameters[li].Dir ection<>pd Input then
adoMain.Parameters[li].Dir ection:=pd Output
adocMain.Parameters[1].Val ue:=ID;
adocMain.Parameters[2].Loa dFromStrea m(lBinStre am , 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('Pi c')).SaveT oStream(lB inStream);
lBinStream.Seek(0, soFromBeginning);
lBitmap.LoadFromStream(lBi nStream);
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
This is how I do the save
var
lBinStream : TMemoryStream;
lBitmap: TBitmap;
li: integer;
begin
lBitmap:=TBitmap.Create;
lBinStream:=TMemoryStream.
lBitmap.LoadFromFile('Some
lBitmap.SaveToStream(lBinS
adoMain.CommandText:='AddP
adoMain.Parameters.Refresh
for li:=1 to adoMain.Parameters.Count-1
if adoMain.Parameters[li].Dir
adoMain.Parameters[li].Dir
adocMain.Parameters[1].Val
adocMain.Parameters[2].Loa
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.
TBlobField(FieldByName('Pi
lBinStream.Seek(0, soFromBeginning);
lBitmap.LoadFromStream(lBi
lBitmap.SaveToFile(c:\pic1
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
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
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
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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
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
ASKER
"The field is too small to accept the amount of data you attempted to add"
K.-P. Becker