Link to home
Start Free TrialLog in
Avatar of lemez
lemez

asked on

How to save the OleContainer content into MS Access database

Hi,

I have a OleContainer and I want save  this OleContainer content into MS Access blobfield.

When I update it I use following source:

  TempStream   := TMemoryStream.Create;
  OleContainer1.SaveToStream(TempStream);
  self.Query1.ParamByName('BLOB').LoadFromStream(TempStream,ftBlob);
  self.Query1.ExecSQL;
  TempStream.Free;

And when I load it

  TempBlobStream := TBlobStream.Create(Query2.FieldByName('BLOB') as TBlobField , bmRead);
  OleContainer1.LoadFromStream(TempBlobStream);
  TempBlobStream.Free;

This source is working in Oracle and Interbase Corectly,
but if i want to use in MS Access it is not working.
For Example :
The OleContainer content a Excel file which size more than 0.5 Mbyte.

I get a next exception : "Access violation ... in modul "ole32.dll".. ".

If you know what is the problem Please answer this question.
ASKER CERTIFIED SOLUTION
Avatar of Rusty_Knight
Rusty_Knight

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of lemez
lemez

ASKER

Thank you,

but I don't know how is it working?
I set the DataSource property and DataField and AutoDisplay=true.

After I insert the excel file to the DBOleContainer2 and call the the query.post method I get a next excpetion "Invalid blob length".
Perhaps did i something wrong?
Example of USE
1. Step. Run at Acess SQL:"create table test
(DATA OleObject)"
2. This is code of test project
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, ExtCtrls, DBCtrls, DB, ADODB, OleCtnrs, DBOLEContainer2,
  ComCtrls, ToolWin;

type
  TForm1 = class(TForm)
    ADOConnection1: TADOConnection;
    ADOTable1: TADOTable;
    DataSource1: TDataSource;
    DBNavigator1: TDBNavigator;
    DBOleContainer21: TDBOleContainer2;
    ToolBar1: TToolBar;
    OpenDialog1: TOpenDialog;
    ToolButton1: TToolButton;
    procedure ToolButton1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.ToolButton1Click(Sender: TObject);
var
 i:integer;
begin
 if OpenDialog1.Execute then begin
   for i:=0 to pred(OpenDialog1.Files.Count) do begin
    ADOTable1.Append;
    DBOleContainer21.CreateObjectFromFile(OpenDialog1.Files[i],False);
    DBOleContainer21.Modify;
    DBOleContainer21.DataSource.DataSet.Post;
   end;
  end;
end;

end.

3. Test Application
3.1. Run Application. DoubleClick on DBOleContainer. After insert object clic on POST button or NEXT or Prev. OLE object will be saved.

3.2. Another Method. Click on button. On Dialog select some files and click OK. All files (OLE) will be saved in Access.
I Import DOC file with size ~4MB
Avatar of lemez

ASKER

Thank you Rusty_Knight.

The different my application and your I used BDE component and not ADO.
Now it is working fine.
lemez:
This old question needs to be finalized -- accept an answer, split points, or get a refund.  For information on your options, please click here-> http:/help/closing.jsp#1 
EXPERTS:
Post your closing recommendations!  No comment means you don't care.
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area for this question:
       to accept Rusty_Knight's answer
Please leave any comments here within the next seven days.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

Some days and here is the Christmas Time. I wish good luck and good health for you all and for your loved ones

kacor
EE Cleanup Volunteer