Read a BlobStream with TADOQuery from an AccessDB

Spread the love

Read a BlobStream with TADOQuery from an AccessDB

function GetBlobStream(Query: TADOQuery): TMemoryStream;
begin
  result := TMemoryStream.Create;

  // You must connect to AccessDB first.
  // See: Query.Connection, TADOConection or Query.ConnectString

  // Send SQL command
  Query.Active := False;
  Query.SQL.Clear;
  // data is my row and email the table
  Query.SQL.Append('SELECT data FROM email WHERE id=1');
  Query.Active := True;

  Result.LoadFromStream(Query.CreateBlobStream(Query.FieldByName('Data'), bmRead));
end;