DB2®ResultSet.ReadRelative Method
Moves the DB2ResultSet to the record that is a specified number of positions away, if the cursor is scrollable.
- Namespace:
IBM.Data.DB2- Assembly:
IBM.Data.DB2(inIBM.Data.DB2.dll)
Syntax
[Visual Basic]
Public Function ReadRelative (Integer position) As Boolean
[C#]
public bool ReadRelative (long position)
[C++]
public:
bool ReadRelative (long position)
[JScript]
public function ReadRelative (position: Integer) : Boolean
Parameters
- position
- The position of the row relative to the current cursor position in the result set.
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.
The current row is refreshed if the offset is zero. A negative offset will move the cursor toward the beginning of the result set. A positive offset will move the cursor toward the end of the result set.
Example
[C#] The following example demonstrates how to determine if the DB2ResultSet instance is scrollable, and then how to read a particular row based on its position relative to the current location of the cursor.
[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.ReadAbsolute(-2);
salesData = salesRS.GetDB2Date(0).ToString();
salesData += ", " + salesRS.GetDB2String(1).ToString();
salesData += ", " + salesRS.GetDB2String(2).ToString();
salesData += ", " + salesRS.GetDB2Int32(3).ToString();
}
}
return salesData;
}