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 (TempStrea m);
self.Query1.ParamByName('B LOB').Load FromStream (TempStrea m,ftBlob);
self.Query1.ExecSQL;
TempStream.Free;
And when I load it
TempBlobStream := TBlobStream.Create(Query2. FieldByNam e('BLOB') as TBlobField , bmRead);
OleContainer1.LoadFromStre am(TempBlo bStream);
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.
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
self.Query1.ParamByName('B
self.Query1.ExecSQL;
TempStream.Free;
And when I load it
TempBlobStream := TBlobStream.Create(Query2.
OleContainer1.LoadFromStre
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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(Se nder: TObject);
var
i:integer;
begin
if OpenDialog1.Execute then begin
for i:=0 to pred(OpenDialog1.Files.Cou nt) do begin
ADOTable1.Append;
DBOleContainer21.CreateObj ectFromFil e(OpenDial og1.Files[ i],False);
DBOleContainer21.Modify;
DBOleContainer21.DataSourc e.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.
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(Se
var
i:integer;
begin
if OpenDialog1.Execute then begin
for i:=0 to pred(OpenDialog1.Files.Cou
ADOTable1.Append;
DBOleContainer21.CreateObj
DBOleContainer21.Modify;
DBOleContainer21.DataSourc
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
ASKER
Thank you Rusty_Knight.
The different my application and your I used BDE component and not ADO.
Now it is working fine.
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.
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
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
ASKER
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?