🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

Problems with empty recordsets

#520
From: George Nakos
Date: Thu, 01 Sep 2005 12:40
80 lines
3082 bytes
Hi people,

I'm very grateful for the suggestions on my previous post, but I have  
stumbled across some stuff about ADO I cannot (yet) comprehend.

The most important one is that I can't handle empty recordsets too good.

The logic I'm currently using in my program, for example, to see if the  
PIN entered by the user exists in the database is to do a simple query on  
the db and if it comes back with an empty recordset, then the PIN doesn't  
exist on a registered user.

My first approach was this:

                     sprintf(send,"SELECT DISTINCT DriverNumber \
 FROM tbl_Drivers Tbl_drivers \
WHERE  DriverNumber = %d",pin);
                     GenQuery->Close();
                     GenQuery->Active=false;
                     GenQuery->SQL->Clear();
                     GenQuery->SQL->Text=send;
                     GenQuery->Open();

I have witnessed, in some other tests of mine, that this throws an  
exception on an empty recordset, and have put it inside a try...catch  
block. Then if an exception isn't thrown, then continue with the program,  
else do something else in the catch handler.

However, this doesn't work with this query. My next idea was to add the  
following lines to the bottom of this code:

                     GenQuery->First();
                     GenQuery->Close();

Here an exception is indeed thrown ("either BOF or EOF is True, or the  
current record has been deleted") and the handler takes care of it, as I  
thought.

But the next time I try to run this query I get an acces violation error  
and the program terminates.

Then I thought of using the RecordCount property, thinking that if the  
record count is zero then there would be no records present, but it  
returns zero no matter what the count.


I know I am doing something very wrong, but I can't figure it out. Can  
anyone help?

BTW I'm using BC++5 and MS Access as the database.


Thanks very much,
George Nakos

-- 
Using Opera's revolutionary e-mail client: http://www.opera.com/mail/
Technical Details
Message-ID: <op.swfb42x5qf2fxd@promitheas.metron.internal>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!news.glorb.com!meganewsservers.com!feeder2.on.meganewsservers.com!news-out.newsgroups.com!propagator2-sterling.newsfeeds.com!in.nntp.be!caladan.landsraad.net!newsgroups.borland.com!not-for-mail

Show Full Headers
Complete Article Headers
X-Google-Thread: 10698b,a3aa13efef982538,start
X-Google-Attributes: gid10698b,public
X-Google-Language: ENGLISH,ASCII-7-bit
Date: Thu, 01 Sep 2005 15:40:04 +0300
Subject: Problems with empty recordsets
Newsgroups: borland.public.cppbuilder.database.ado
From: "George Nakos" <gnakos@metronco.gr>
Organization: Metron LTD
Content-Type: text/plain; format=flowed; delsp=yes; charset=iso-8859-7
MIME-Version: 1.0
Content-Transfer-Encoding: Quoted-Printable
Message-ID: <op.swfb42x5qf2fxd@promitheas.metron.internal>
User-Agent: Opera M2/8.10 (Win32, build 7685)
NNTP-Posting-Host: 83.235.222.66
X-Trace: newsgroups.borland.com 1125578295 83.235.222.66 (1 Sep 2005 05:38:15 -0700)
Lines: 80
Path: arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!news.glorb.com!meganewsservers.com!feeder2.on.meganewsservers.com!news-out.newsgroups.com!propagator2-sterling.newsfeeds.com!in.nntp.be!caladan.landsraad.net!newsgroups.borland.com!not-for-mail