Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 456
  • Last Modified:

Post to BLOB in MS Access using TADODataset

Here is my code:
procedure TForm1.btnAddBlobClick(Sender: TObject);
var
st1:TStream; //ole1:Olecontainer, rst:TADODataSet in my form, rst.Fields[0]=blob

begin
   try
      ole1.InsertObjectDialog;
      rst.Append;
      st1:=rst.CreateBlobStream(rst.Fields[0],bmReadWrite);
      ole1.SaveToStream(st1);
            rst.Post;
   finally
      st1.Free;
   end;
end;

I am getting error that empty row can not be inserted. What's wrong?


0
bogiboy
Asked:
bogiboy
1 Solution
 
Lee_NoverCommented:
you probably have some fields in the table that MUST have a value
0
 
bogiboyAuthor Commented:
only fields that i have are Key (autoinc) and BLOB, also, I tried with BLOB foield as the only one in the table...same problem
0
 
Lee_NoverCommented:
weird
have you tried using .Insert ?
I had the same problem but I don't remember how I solved it :)
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
swift99Commented:
I remember having the same problem and it went away when I switched to any non-Access DBMS.  At that point I stopped using Access as a back end for my own apps.
0
 
kretzschmarCommented:
access stores blobs with an ole-server information prefix.

if there is no need to access the content within the access-frontend, then you should be able to store
your content simple with

tblobfield(dataset.fieldbyname('fieldname')).loadfromfile('filename');  //or loadfromstream

savetofile/savetostream for the other direction

meikl ;-)
0
 
bogiboyAuthor Commented:
Kretzschmar, you answered my problem. Using st1:=rst.CreateBlobStream(Tfield,mode) I couldn't do anything, but using TBlobField(...) syntacs -it works. Still wondering why.
NOTE: Make sure that you declare stream as TMemoryStream, not TStream to load document into OleContainer. When used TStream, I got "Stream read error" so I did typecast in OpenDoc procedure and it started to work. The same applies to AddDoc procedure.

Here is my code to:
1) Load document and post it to a blob field
2) Load it from DB and run it using OLEContainer

procedure TForm1.btnAddClick(Sender: TObject);
var
st:TMemoryStream;
begin
try
 st:=TMemoryStream.Create;
rst.Open;
Ole1.SaveToStream(St);
rst.Append;
TBlobField(rst.FieldByName('Document')).LoadFromStream(st);
rst.Post;
   finally
    st.Free;
  end;
end;

procedure TForm1.ButtonOpenDoc(Sender: TObject);
var
str:TMemoryStream;
begin
   try
   str:=TMemoryStream.Create;
   str:=TMemoryStream(rst.CreateBlobStream(rst.FieldByName('Document'),bmRead));
   ole1.LoadFromStream(str);
   ole1.Iconic:=False;
   ole1.DoVerb(0);
   finally
      str.Free;
   end;
end;
0

Featured Post

Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now