0

It seems folks have lost the ability to generate old style COBOL/RPG reports using modern day languages.

I often see code using DataReaders that relies on a count of records. So an additional aggregrate query is present when it need not be.

In most circumstance this code needs to know if there is another record available or not. In other words, tell me if I'm at the last record so I can display a record separator.

A simple algorithm would be as follows:


Dim available As Boolean = rdr.Read()
While available
  DisplaySearchRecord(rdr)
  available = rdr.Read()
  If available Then DisplaySeparator()
End While

Please, do not use COUNT(*) or a datatable/dataset when a simple change in algorithm will suffice.

4

3 に答える 3

0

?の後にセパレータを表示しないのはなぜwhileですか?

   While rdr.Read()
       DisplaySearchRecord(rdr)
   End While
   DisplaySeparator()
于 2009-04-23T14:15:33.847 に答える
0

あなたはこのようなことを試すことができます

Dim IsFirst As Boolean = True

While rdr.Read()
  If Not IsFirst
    DisplaySeparator()
  Else
    IsFirst = False
  End If

  DisplaySearchRecord(rdr)
End While
于 2009-04-23T14:18:28.537 に答える
0

reader.Read()を呼び出し続ける必要があり、レコードがなくなるとfalseが返されます。

したがって、私が行うことは、データをデータベースからaにダンプしList<YourRecord>、リストにデータを入力した後、for(i ++)ループで反復し、iをlist.Countと照合します。

于 2009-04-23T14:19:12.933 に答える