Solved

Can't use RecNo ... alternatives?

Posted on 1998-07-06
5
348 Views
Last Modified: 2010-04-04
The RecNo function function does not work with my queries (Oracle).

I would like to be able to display to my users a "Record 1 of 9"  message as they scroll through the DBControlGrid.
I can use RecordCount to get the "of 9" part but short of a complicated algorithm (bookmarking, looping thre dataset, etc) to determine record position each time the user adds/deletes/scrolls have not been able to find a replacement for the RecNo function.  

Any suggestions?
0
Comment
Question by:djake021198
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 1

Expert Comment

by:Greedy
ID: 1357187
Some Oracal Guru will probably know a better way but here are two ways to solve it...once again considering speed it's super important here since your giving back user input this once again implies that it only has to be as fast as a human...

this first way can be used if you can't change the structure of your Oracal table

procedure TForm1.Button1Click(Sender: TObject);
var
  MyCounter: Integer;
  Found: Boolean;
begin
  MyCurrentRecordKey := Table1.FieldByName('YourPrimaryIndexField').AsString;
  Table1.DisableControls;
  Table1.First;
  MyCounter := 1;
  Found := False;
  While (not Table1.EOF) and (not Found) do
  begin
    if MyCurrentRecordKey = Table1.FieldByName('YourPrimaryIndexField').AsString then
      Found := True
    else
    begin
      Table1.Next;
      inc(MyCounter);
    end;
  end;
  Table1.EnableControls;
  Label1.Caption := IntToStr(MyCounter);
end;

Now a better way (faster) to do this would be to add a field called RecordNumber and then just return this in your UpDateLabel routine.  You will also have to make calls to renumber all the records when they do a delete or an insert but that's not too bad just a while loop and a counter... now I keep talking about speed but please note that both of these methods take less than half a second to compleate on my database of about 30,000 records running on a small MSSQL server useing SQL Links so I would bet Oracal shaves another .1 sec off this you can also use TQueries to do this stuff for at least another .2 sec off the times.  Have you looked to see if the Oracal site has any help on this yet?

0
 
LVL 3

Expert Comment

by:KE
ID: 1357188
I don't know much of Oracle servers, but maybee you could make a stored procedure which returns your rows (of course) but also a programatically generated record number. This is just an idea !!!

0
 
LVL 3

Expert Comment

by:vladika
ID: 1357189
There is RowNum statement in the Oracle.
Try use it in your query

select RowNum, ..... from ....


0
 
LVL 5

Expert Comment

by:ronit051397
ID: 1357190
You should ask this question in the Oracle forum, maybe they will tell you the correct sql statement/s.
0
 
LVL 1

Accepted Solution

by:
bozo7 earned 100 total points
ID: 1357191
I got around this by using the following code (example)

function Function1:INteger;
begin
 query1.sql.add('select (count(*)) Count from table1);
 query1.prepare;
 query1.open;
 result := fieldbyname('Count').value;
end;

I ran into the same thing going from Interbase to oracle. This was the best way to do it.
Bozo
0

Featured Post

Want Experts Exchange at your fingertips?

With Experts Exchange’s latest app release, you can now experience our most recent features, updates, and the same community interface while on-the-go. Download our latest app release at the Android or Apple stores today!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
Suggested Courses
Course of the Month9 days, 21 hours left to enroll

624 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question