Board index » delphi » RecordCount Error

RecordCount Error


2004-04-16 03:07:46 PM
delphi231
Hi All,
Please help me. I am getting the following error on RecordCount:
"dbExpress Error: Operation Not Supported"
This is my Code:
x := 0;
//Generate Reference Number
with DataModuleForm do
begin
Query1.SQL.Clear;
Query1.SQL.Add('SELECT TheDate FROM Quotes Where TheDate = :Date');
Query1.Params.ParamValues['Date'] := x;
Query1.Open;
x := Query1.RecordCount;
end;
RefNoBox.Text :=
FormatDateTime('"'+IntToStr(x)+'."dd.mm.yyyy',TheDatePicker.Date);
thanx,
Peet
 
 

Re:RecordCount Error

If Query1 it is a unidirectional dataset (like TSqlQuery or TSqlDataSet) I
think that is not a good idea read RecordCount. You can try with a SELECT
COUNT.
I'm reading the borland help (about RecordCount) and say:
"Reading RecordCount will generate an exception if the dataset can't
determine the number of records. Do not read RecordCount if:
1. The dataset represents stored procedure.
2. The dataset represents a query that contains parameters.
3. The dataset represents a multi-table join."
Angelyy
"Peet Koekemoer" <XXXX@XXXXX.COM>escribi?en el mensaje
Quote
Hi All,

Please help me. I am getting the following error on RecordCount:
"dbExpress Error: Operation Not Supported"
This is my Code:

x := 0;

//Generate Reference Number
with DataModuleForm do
begin
Query1.SQL.Clear;
Query1.SQL.Add('SELECT TheDate FROM Quotes Where TheDate = :Date');
Query1.Params.ParamValues['Date'] := x;
Query1.Open;
x := Query1.RecordCount;
end;
RefNoBox.Text :=
FormatDateTime('"'+IntToStr(x)+'."dd.mm.yyyy',TheDatePicker.Date);

thanx,
Peet


 

Re:RecordCount Error

The problem is that, as TSqlQuery is a "single record container",
there is no way to know how many record CAN be fetched. So Borland
implemented a "RecordCount guess" creating a
SELECT COUNT(*) FROM adding to it the name of your table and your
WHERE clause.
Of course it can be done only if the query is very simple (single
table, no parameters, ...), in all the other cases the resulting
syntax could be (is) wrong.
Regards
Paolo
"Angelyy" <XXXX@XXXXX.COM>writes
Quote
If Query1 it is a unidirectional dataset (like TSqlQuery or
TSqlDataSet) I
think that is not a good idea read RecordCount. You can try with a
SELECT
COUNT.

I'm reading the borland help (about RecordCount) and say:
"Reading RecordCount will generate an exception if the dataset can't
determine the number of records. Do not read RecordCount if:
1. The dataset represents stored procedure.
2. The dataset represents a query that contains parameters.
3. The dataset represents a multi-table join."

Angelyy


"Peet Koekemoer" <XXXX@XXXXX.COM>escribi?en el mensaje
news:XXXX@XXXXX.COM...
>Hi All,
>
>Please help me. I am getting the following error on RecordCount:
>"dbExpress Error: Operation Not Supported"
>This is my Code:
>
>x := 0;
>
>//Generate Reference Number
>with DataModuleForm do
>begin
>Query1.SQL.Clear;
>Query1.SQL.Add('SELECT TheDate FROM Quotes Where TheDate =
:Date');
>Query1.Params.ParamValues['Date'] := x;
>Query1.Open;
>x := Query1.RecordCount;
>end;
>RefNoBox.Text :=
>FormatDateTime('"'+IntToStr(x)+'."dd.mm.yyyy',TheDatePicker.Date);
>
>thanx,
>Peet
>
>


 

Re:RecordCount Error

Dave Rowntree writes:
Quote
A lot has already been written about this in these newsgroups. Have a
look in the newsgroup archives (e.g. www.google.com) for more info.
Why record counting is bad and how to avoid it:
delphi.weblogs.com/stories/storyReader$387#RecordCounting
-Craig
--
Craig Stuntz [TeamB] . Vertex Systems Corp. . Columbus, OH
Delphi/InterBase Weblog : delphi.weblogs.com
InterBase in Multi-tier World -- Use multiple RDMs, IB features in
your appserver: delphi.weblogs.com/stories/storyReader$195