🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.cppbuilder.database.ado
Article #91

Re: Database problem

#91
From: Tomislav Hundric'
Date: Sat, 28 Jul 2007 17:47
134 lines
6905 bytes
Again I want to thank you Vassiliev,
I did what you suggested, and I save .jpg images from my app to db using 
following onClick button event:

   if (OpenPictureDialog1->Execute())
   {
     ADOQuery1->Edit();
     TBlobField* field = (TBlobField*)ADOQuery1->FieldByName("FIELDNAME");
     field->LoadFromFile(OpenPictureDialog1->FileName);
     ADOQuery1->Post();
   }

and this works as expected, no errors and when I open db in ms access I 
can confirm that picture has been saved (it says Long Binary Data). 
However I still get error "Invalid class typecast" when I try to load 
image, I've tried to google for this error and I didn't find any 
solutions or workarounds for this problem. I've searched through 
borland.public.cppbuilder.graphics news group and there was mentioned 
that this solution should work, but for some reason which is enigma to 
me my app breaks at:

TBlobStream* stream = new TBlobStream(field, bmRead);

I don't know if you can help me with this one, I really appreciate your 
help so far.

Thanks in advance,
Tomislav.



Vassiliev V. V. wrote:
> Access saves not only jpeg file but also ActiveX information. So if you save 
> jpeg from your program and load it later it will work, but save jpeg from 
> Access UI and load will not work (jpeg should be stored in BLOB with some 
> offset, for bitmap offset was 78 if I am not wrong but it is not constant), 
> and save jpeg from your program will not allow to view it from Access UI. 
> You may look for third-party components to save BLOBs in format compatible 
> with Access UI. However if you do not need Access UI just work with BLOBs as 
> from any other DBMS.
> 
> //------------------------------------------
> Regards,
> Vassiliev V. V.
> http://www.managed-vcl.com - using .Net objects in Delphi for Win32 +
> ADO.Net
> http://www.oledbdirect.com - The fastest way to access MS SQL Server,
> MS Jet (Access) and Interbase (through OLEDB)
> 
> 
> "Tomislav Hundric'" <rifnet@gmail.com> �������/�������� � �������� 
> ���������: news:46ab24f1@newsgroups.borland.com...
>> Hi Vassiliev,
>> thanks on your quick response. I'm sorry if I'm asking too much, but am I 
>> doing it right, I create blank database and table with two fields, ID 
>> (autonumber) and IMG(OLE OBJECT), for starters I'm filling IMG field via 
>> MS Access, so I right click on IMG field and select Insert Object... 
>> Create from file and then I choose .jpg file which I want to add. In 
>> c++builder 6, I have a form with dbImage and button:
>>
>> I've included:
>> #include <jpeg.hpp>
>>
>> and register class on form create event:
>> DBImage1->Picture->RegisterFileFormat(__classid(TJPEGImage), "jpg", "JPEG 
>> File", __classid(TJPEGImage));
>>
>> DBImage control AutoDisplay property is set to false, and on buttonClick 
>> event I have:
>>
>>     TBlobField* field = (TBlobField*)ADOQuery1->FieldByName("IMG");
>>     TBlobStream* stream = new TBlobStream(field, bmRead);
>>     TJPEGImage* image = new TJPEGImage;
>>     DBImage1->Picture->Assign(image);
>>     DBImage1->Picture->Graphic->LoadFromStream(stream);
>>     delete stream;
>>     delete image;
>>
>> When I click on button, I get error "Invalid class typecast", I can't 
>> figure out what's wrong, can you tell me if this approach is ok, or I 
>> should do it in some other way.
>>
>> Thanks in advance,
>> Tomislav.
>>
>>
>> Vassiliev V. V. wrote:
>>> Access (Jet engine) does support BLOBs. Just in MS Access UI you will see 
>>> it not as OLE object but as binary data (i.e. can not normally view in MS 
>>> Access UI). Inside your application it will be normal BLOB as in most 
>>> other DBMS.
>>>
>>> //------------------------------------------
>>> Regards,
>>> Vassiliev V. V.
>>> http://www.managed-vcl.com - using .Net objects in Delphi for Win32 +
>>> ADO.Net
>>> http://www.oledbdirect.com - The fastest way to access MS SQL Server,
>>> MS Jet (Access) and Interbase (through OLEDB)
>>>
>>>
>>> "Tomislav Hundric" <rifnet@gmail.com> �������/�������� � �������� 
>>> ���������: news:46aaee61@newsgroups.borland.com...
>>>> Hi,
>>>> I have the following situation. I have to develop application that will 
>>>> be used to display images and data from db. My first thought was I'll 
>>>> use ms access db because it is very simple to deploy, only one file and 
>>>> the best part is I don't have to install bde engine since it uses 
>>>> microsoft jet driver which is native in windows, but since ms access 
>>>> doesn't have blob field I have to use OLE object and I found out that it 
>>>> converts jpeg images to bmp and increases size of db dramatically. I 
>>>> know I can use save the path to file in db field and then retrieve the 
>>>> image stored locally, but this is not a good solution to me since I'll 
>>>> be storing hundreds of images so I want to avoid hundreds of files 
>>>> stored locally. My next thought was to use paradox db since it is able 
>>>> to store images in blob field, but I want to avoid installation of bde 
>>>> if possible. I've came across this article which says:
>>>>
>>>> Jet 4.0 supports connections to Paradox 3, 4 and 5 only; we do not 
>>>> support later versions. The ADO connection string syntax would be:
>>>>
>>>> cnn.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & _ "Data
>>>> Source=c:\somepath;" & _ "Extended Properties=Paradox 5.x;"
>>>>
>>>> I've tried the connection string above and I get error:
>>>> Could not find installable ISAM
>>>>
>>>> Does anyone know is it possible to connect to paradox db using jet 
>>>> drivers (ADO Connection), or can anyone suggest me which is the best way 
>>>> to solve my problem.
>>>>
>>>> Thanks in advance,
>>>> Tomislav
> 
Technical Details
Message-ID: <46ab8171@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!g2news2.google.com!news2.google.com!news.glorb.com!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail
References: <46aaee61@newsgroups.borland.com> <46ab0ca8$1@newsgroups.borland.com> <46ab24f1@newsgroups.borland.com> <46ab5b98@newsgroups.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Thread: 10698b,723ca8957fa3ed73
X-Google-Attributes: gid10698b,public,usenet
X-Google-Language: ENGLISH,CP1252
Date: Sat, 28 Jul 2007 19:47:56 +0200
From: Tomislav Hundric' <rifnet@gmail.com>
User-Agent: Thunderbird 2.0.0.0 (Windows/20070326)
MIME-Version: 1.0
Newsgroups: borland.public.cppbuilder.database.ado
Subject: Re: Database problem
References: <46aaee61@newsgroups.borland.com> <46ab0ca8$1@newsgroups.borland.com> <46ab24f1@newsgroups.borland.com> <46ab5b98@newsgroups.borland.com>
In-Reply-To: <46ab5b98@newsgroups.borland.com>
Content-Type: text/plain; charset=windows-1252; format=flowed
Content-Transfer-Encoding: 8bit
NNTP-Posting-Host: 78.0.149.42
Message-ID: <46ab8171@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1185644913 78.0.149.42 (28 Jul 2007 10:48:33 -0700)
Lines: 134
Path: arc1-ca.pugleaf.net!g2news2.google.com!news2.google.com!news.glorb.com!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail