我的代码如下
//将数据库中的BLOB对象显示在olecontainer中,adoBLOB为TADODataSet组件,oleMain为
//TOLEContainer组件
var
Ms:TMemoryStream;
begin
Sql := 'Select * from T_BLOB where to_char(BLOB_ID)='''+IntToStr(BLOBID)+'''';
with adoBLOB do
begin
Close;
CommandText := Sql;
Open; Ms := TMemoryStream(adoBLOB.CreateBlobStream(adoBLOB.FieldByName
('BLOB_OBJECT'),bmRead));
TBlobField(adoBLOB.FieldByName('BLOB_OBJECT')).SaveToStream(Ms);
olecMain.LoadFromStream(Ms);
Ms.Free;
end;
end;错误提示为:Stream read error我测试了一下,问题出在olecMain.l.LoadFromStream(Ms);这句话,也就是blob对象已经可以取到Sream中,但是用olecontainer去读取的时候就出错了,请高手指点,错误在哪里?刚才在olecMain.LoadFromStream(Ms);这句前面加了两句话
Ms.Position := 0;
Ms.Size;
还是不行
//将数据库中的BLOB对象显示在olecontainer中,adoBLOB为TADODataSet组件,oleMain为
//TOLEContainer组件
var
Ms:TMemoryStream;
begin
Sql := 'Select * from T_BLOB where to_char(BLOB_ID)='''+IntToStr(BLOBID)+'''';
with adoBLOB do
begin
Close;
CommandText := Sql;
Open; Ms := TMemoryStream(adoBLOB.CreateBlobStream(adoBLOB.FieldByName
('BLOB_OBJECT'),bmRead));
TBlobField(adoBLOB.FieldByName('BLOB_OBJECT')).SaveToStream(Ms);
olecMain.LoadFromStream(Ms);
Ms.Free;
end;
end;错误提示为:Stream read error我测试了一下,问题出在olecMain.l.LoadFromStream(Ms);这句话,也就是blob对象已经可以取到Sream中,但是用olecontainer去读取的时候就出错了,请高手指点,错误在哪里?刚才在olecMain.LoadFromStream(Ms);这句前面加了两句话
Ms.Position := 0;
Ms.Size;
还是不行
procedure TForm1.Button1Click(Sender: TObject);
var
s:TMemorystream;
begin
s:=TMemorystream.Create;
olecontainer1.SaveToStream(s);
ADOQuery1.Close;
ADOQuery1.SQL.Clear;
ADOQuery1.SQL.Add('insert into dwg (images) VALUES (:tmpcad)');
ADOQuery1.Parameters.ParamByName('tmpcad').LoadFromStream(s,ftBlob);
ADOQuery1.Prepared;
ADOQuery1.ExecSQL;
s.Free;
showmessage('保存成功!');
end;
//从sql server读出
procedure TForm1.Button2Click(Sender: TObject);
var
s:Tstream;
begin
ADOQuery1.Close;
ADOQuery1.SQL.Clear;
ADOQuery1.SQL.Add('select images from dwg where id =5');
ADOQuery1.Prepared;
ADOQuery1.Open;
with ADOQuery1 do
s:=CreateBlobStream(ADOQuery1.FieldByName('images'),bmRead);
olecontainer2.LoadFromStream(s);
olecontainer2.SaveToFile('aaa.dwg');
s.Free;
end;