to:dadabox,ji_xuegang
1.表结构
create table myimages(
filename varchar2(30),
enterdate date,
image blob);
2. use stream
...
try
Mystream:=Tmemorystream.creat;
MyStream.loadfromfile(Filename);
MyStream.position:=0;
Database1.Open;
database1.StartTransaction;
try
WITH Query1 do
begin
Close;
SQL.Clear;
SQL.Add('INSERT INTO myimages VALUES
filename,:enterdate ,:newimage)');
ParamByName('filename').AsString:=GetFileName(Filename);
ParamByName('enterdate').AsDateTime:=Now;
ParamByName('newimage').LoadFromStream(MyStream,ftBlob);
ExecSQL;
end;
Database1.Commit;
except
On E: EDBEngineError do
{异常处理}
....
finally
mystream.free;
end;
3. use DOA
.....
var LOB: TLOBLocator;
Buffer: array[0..99] of Byte;
begin
// insert into lobtable (id, lobcolumn) values
id, empty_blob())
// returning lobcolumn into :lobcolumn
with LOBQuery do
begin
SetVariable('id', 1);
// Create a new BLOB (initially Null)
LOB := TLOBLocator.Create(Session, otBLOB);
// Assign it to the returning variable
SetComplexVariable('lobcolumn', LOB);
Execute;
// After the insert, use the LOB Locator to write the data
LOB.Write(Buffer, 100);
LOB.Free;
end;
end;
4. 显示图像可以使用Tdbimage ,取数据和存数据过程相反。