to barton:
请帮忙看一下下面的代码是否有错。我有时没报错,但数据库中也没有保存,
我的服务端用的就是IBSQL。
var
str1:string;
Stream1: TMemoryStream;
Stream2: TStream;
bmp:tbitmap;
begin
str1:= ' select bmpindex,bitmap from bmpdata WHERE bmpindex = 26266 ' ;
// bitmap为 BLOB SUB_TYPE 0 SEGMENT SIZE 80,
str1:=str1+ '''' + DZBM +'''';
with dm1do
begin
ClientDataSet1.Close;
ClientDataSet1.CommandText:=str1;
ClientDataSet1.open;
if not (ClientDataSet1.State in [dsInsert, dsEdit]) then
ClientDataSet1.Edit ;
Stream1:= TMemoryStream.Create();
bmp:=tbitmap.Create ;
try
bmp.LoadFromFile('C:/WINDOWS/web/wvleft.bmp');
bmp.SaveToStream(Stream1);
Stream1.Position :=0;
Stream2 := ClientDataSet1.CreateBlobStream( ClientDataSet1.FieldByName('bitmap'), bmReadWrite);
try
Stream2.CopyFrom(Stream1, Stream1.Size);
ClientDataSet1.Post;
ClientDataSet1.ApplyUpdates(0);
finally
Stream2.Free;
end;
finally
Stream1.Free;
bmp.free;
end;
end;
end;