Solved

Can't use RecNo ... alternatives?

Posted on 1998-07-06
5
340 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
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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
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…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

707 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now