DB2®ResultSet.ReadPrevious Method

Moves the DB2ResultSet to the previous record, if the cursor is scrollable.

Namespace:
IBM.Data.DB2
Assembly:
IBM.Data.DB2 (in IBM.Data.DB2.dll)

Syntax


[Visual Basic]
Public Function Read As Boolean
[C#]
public bool Read ()
[C++]
public:
bool Read ()
[JScript]
public function Read () : Boolean

Return value

true if the newly assumed position has a record (regardless if it was deleted); otherwise, false.

Remarks

The cursor must be positioned in the result set, otherwise running this method will throw an exception.

Example

[C#] The following example demonstrates how to read the second-last row from the result set.

[C#]
  public static string getSalesData(DB2Connection conn)
  {
    string salesQuery = "SELECT * FROM SALES";
    string salesData = "";
    DB2Command cmd = new DB2Command(salesQuery, conn);
    DB2ResultSet salesRS = cmd.ExecuteResultSet(
      DB2ResultSetOptions.Scrollable |
      DB2ResultSetOptions.Sensitive |
      DB2ResultSetOptions.SkipDeleted);

    if (salesRS.Scrollable)
    {
      if (salesRS.ReadLast())
      {
        salesRS.ReadPrevious();
        salesData = salesRS.GetDB2Date(0).ToString();
        salesData += ", " + salesRS.GetDB2String(1).ToString();
        salesData += ", " + salesRS.GetDB2String(2).ToString();
        salesData += ", " + salesRS.GetDB2Int32(3).ToString();
      }
    }

    return salesData;
  }