Thread View: borland.public.cppbuilder.database.ado
3 messages
3 total messages
Started by George Nakos
Thu, 01 Sep 2005 12:40
Problems with empty recordsets
Author: George Nakos
Date: Thu, 01 Sep 2005 12:40
Date: Thu, 01 Sep 2005 12:40
80 lines
3082 bytes
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/
Re: Problems with empty recordsets
Author: Arnie
Date: Thu, 01 Sep 2005 13:03
Date: Thu, 01 Sep 2005 13:03
33 lines
1912 bytes
1912 bytes
George Nakos wrote:
> 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.
>
This probably indicates you need the ADO patch from Borland. BCB
5 had two patches, one for the product in general and one for
ADO.
>
> BTW I'm using BC++5 and MS Access as the database.
>
sprintf(send,"SELECT DISTINCT DriverNumber \
FROM tbl_Drivers Tbl_drivers \
WHERE DriverNumber = %d",pin);
GenQuery->Close();
GenQuery->Active=false; // You don't
need this. Close() has already done this
GenQuery->SQL->Clear();
GenQuery->SQL->Text=send;
GenQuery->Open();
if ( GenQuery->Eof )
// ID doesn't exist
- Arnie
Re: Problems with empty recordsets
Author: George Nakos
Date: Thu, 01 Sep 2005 13:29
Date: Thu, 01 Sep 2005 13:29
35 lines
2033 bytes
2033 bytes
On Thu, 01 Sep 2005 16:03:44 +0300, Arnie <none> wrote: > This probably indicates you need the ADO patch from Borland. BCB > 5 had two patches, one for the product in general and one for > ADO. Just did it! > >> >> BTW I'm using BC++5 and MS Access as the database. >> > > sprintf(send,"SELECT DISTINCT DriverNumber \ > FROM tbl_Drivers Tbl_drivers \ > WHERE DriverNumber = %d",pin); > GenQuery->Close(); > GenQuery->Active=false; // You don't > need this. Close() has already done this > GenQuery->SQL->Clear(); > GenQuery->SQL->Text=send; > GenQuery->Open(); > > if ( GenQuery->Eof ) > // ID doesn't exist > Now it seems to be working. Thanks for the tips! George -- Using Opera's revolutionary e-mail client: http://www.opera.com/mail/
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads