DB2®ResultSet.ReadFirst Method
Moves the DB2ResultSet to the first record, if the cursor is scrollable.
- Namespace:
IBM.Data.DB2
- Assembly:
IBM.Data.DB2
(inIBM.Data.DB2.dll
)
Syntax
[Visual Basic]
Public Function ReadFirst As Boolean
[C#]
public bool ReadFirst ()
[C++]
public:
bool ReadFirst ()
[JScript]
public function ReadFirst () : Boolean
Return value
true
if
the newly assumed position has a record (regardless if it was deleted);
otherwise, false
.
Remarks
For non-scrollable cursors, the ReadFirst method
will return true
and move to the first record if
the cursor has not yet read a record from the result set. If the cursor
is on the first row of the result set, ReadFirst will
return true
and remain on the first row. If the cursor
is on any other row in the result set, ReadFirst will
throw an exception.
The default position of the DB2ResultSet is before the first record. Therefore, you must call Read, ReadFirst, ReadLast, or ReadAbsolute before any data.
Example
[C#] The following example demonstrates how to determine if the DB2ResultSet instance is scrollable, and then how to read the first row in 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.ReadFirst())
{
salesData = salesRS.GetDB2Date(0).ToString();
salesData += ", " + salesRS.GetDB2String(1).ToString();
salesData += ", " + salesRS.GetDB2String(2).ToString();
salesData += ", " + salesRS.GetDB2Int32(3).ToString();
}
}
return salesData;
}