🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

Re: Database problem

#92
From: Vassiliev V. V.
Date: Sat, 28 Jul 2007 20:30
153 lines
8043 bytes
May be field is not TBlobField? Check type of ADOQuery1->FieldByName("IMG"). 
Try also TBlobField->SaveToStream() instead of create TBlobStream, or use 
ADOQuery1->CreateBlobStream() instead of create TBlobStream - dbGo (ADO 
components) have own TADOBlobStream and are probably incompatible with 
TBlobStream.

//------------------------------------------
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:46ab8171@newsgroups.borland.com...
> 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: <46aba785@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!g2news2.google.com!news3.google.com!proxad.net!feeder1-2.proxad.net!213.200.89.82.MISMATCH!tiscali!newsfeed1.ip.tiscali.net!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail
References: <46aaee61@newsgroups.borland.com> <46ab0ca8$1@newsgroups.borland.com> <46ab24f1@newsgroups.borland.com> <46ab5b98@newsgroups.borland.com> <46ab8171@newsgroups.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Thread: 10698b,723ca8957fa3ed73
X-Google-Attributes: gid10698b,public,usenet
X-Google-Language: ENGLISH,ASCII
From: "Vassiliev V. V." <support@oledbdirect.com>
Newsgroups: borland.public.cppbuilder.database.ado
References: <46aaee61@newsgroups.borland.com> <46ab0ca8$1@newsgroups.borland.com> <46ab24f1@newsgroups.borland.com> <46ab5b98@newsgroups.borland.com> <46ab8171@newsgroups.borland.com>
Subject: Re: Database problem
Date: Sun, 29 Jul 2007 00:30:24 +0400
Lines: 155
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2900.3138
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.3138
X-RFC2646: Format=Flowed; Response
X-Antivirus: avast! (VPS 000761-3, 28.07.2007), Outbound message
X-Antivirus-Status: Clean
NNTP-Posting-Host: 85.93.138.132
Message-ID: <46aba785@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1185654661 85.93.138.132 (28 Jul 2007 13:31:01 -0700)
Path: arc1-ca.pugleaf.net!g2news2.google.com!news3.google.com!proxad.net!feeder1-2.proxad.net!213.200.89.82.MISMATCH!tiscali!newsfeed1.ip.tiscali.net!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail