Solved

Post to BLOB in MS Access using TADODataset

Posted on 2002-06-06
6
450 Views
Last Modified: 2012-06-21
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
Comment
Question by:bogiboy
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 12

Expert Comment

by:Lee_Nover
ID: 7060129
you probably have some fields in the table that MUST have a value
0
 
LVL 1

Author Comment

by:bogiboy
ID: 7060557
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
 
LVL 12

Expert Comment

by:Lee_Nover
ID: 7060601
weird
have you tried using .Insert ?
I had the same problem but I don't remember how I solved it :)
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 6

Expert Comment

by:swift99
ID: 7061185
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
 
LVL 27

Accepted Solution

by:
kretzschmar earned 100 total points
ID: 7061217
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
 
LVL 1

Author Comment

by:bogiboy
ID: 7062592
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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Come and listen to Percona CEO Peter Zaitsev discuss what’s new in Percona open source software, including Percona Server for MySQL (https://www.percona.com/software/mysql-database/percona-server) and MongoDB (https://www.percona.com/software/mongo-…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…

689 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question