Solved

Can't use RecNo ... alternatives?

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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

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…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

751 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