Article View: borland.public.cppbuilder.database.ado
Article #85Read/write BLOB fields using ADO
From: Mike K
Date: Mon, 18 Feb 2008 20:05
Date: Mon, 18 Feb 2008 20:05
55 lines
2483 bytes
2483 bytes
I'm trying to retrieve a block of binary data (~5k bytes) from a SQL
Server database table. The column name is 'data'.
Using TADOQuery, I want to read the record, and write the data from the
result set into memory. Also, I need to do the reverse (write the
record). This should not be rocket science.
Here's what I have so far after a day and a half experimenting with
snippets from old newsgroup posts:
<snip>
typedef struct{
...
}CONFIG_DATA;
CONFIG_DATA *cp;
TADOQuery *iQuery;
TBlobStream *bptr;
iQuery->Active = false;
iQuery->SQL->Clear();
// just get one record:
iQuery->SQL->Add("select data from config_data where ID = 3001");
iQuery->Active = true;
// got a runtime error before I put this line in:
iQuery->Edit();
bptr =
dynamic_cast<TBlobStream*>(iQuery->CreateBlobStream(iQuery->FieldByName("data"),bmRead));
if(bptr) bptr = ReadBuffer(cp,bptr->Size);
// home free if you get here!
<end snip>
Works fine until I get to CreateBlobStream(), which returns a null
pointer. I've tried tons of methods to create the TBlobStream pointer,
none of which work, many of which won't even compile (taken straight
from BCB5 help).
This should not be difficult, but I'm having no luck. I have been using
ADO database objects with BCB5 for years, just never had large binary
fields.
Any kind soul who is willing to either give me the few lines of code I
need, or point me to a SPECIFIC WORKING example anywhere cyberspace, I
will happily add you to my Christmas card list (it's too late for a
valentine).
TIA
Mike
Technical Details
Message-ID:
<47b9e51b$1@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!g2news1.google.com!news4.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-mailShow Full Headers
Complete Article Headers
X-Google-Thread: 10698b,1c341601eb4e7a8a,start X-Google-Attributes: gid10698b,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Date: Mon, 18 Feb 2008 14:05:49 -0600 From: Mike K <nospam@nospam.net> User-Agent: Thunderbird 1.5.0.14 (Windows/20071210) MIME-Version: 1.0 Newsgroups: borland.public.cppbuilder.database.ado Subject: Read/write BLOB fields using ADO Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit NNTP-Posting-Host: 74.38.241.126 Message-ID: <47b9e51b$1@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1203365147 74.38.241.126 (18 Feb 2008 12:05:47 -0700) Lines: 61 Path: arc1-ca.pugleaf.net!g2news1.google.com!news4.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