SqlCeResultSet.ReadAbsolute Method
Moves the reader to a specific record in the ResultSet.
Namespace: System.Data.SqlServerCe
Assembly: System.Data.SqlServerCe (in System.Data.SqlServerCe.dll)
Parameters
- position
- Type: System.Int32
The position to which to move the reader.
ReadAbsolute is 0-based; calling ReadAbsolute(0) will return the first row of the ResultSet.
This method reads the value of the row based on the row position saved by a bookmark. For example, suppose you have a table with 10 rows, and you open two ResultSets: rs1 and rs2. You call ReadAbsolue(5) on rs1 and change the value of this row to -1. The row's position has now changed to the first position in the list of rows, and row 4 is in the 5th position. However, if you now call ReadAbsolute(5) on rs2, a value of -1 is returned. ResultSet rs2 maintains a bookmark to the original 5th row and continues to read that row, despite its position changing.
If you pass a positive integer to this function, the reader is moved from the first record forward the specified number of records. If you pass a negative integer to this function, the reader is moved from the last record back the specified number of records.
The following example creates a ResultSet object and then calls several methods, including ReadAbsolute.
SqlCeConnection conn = null; try { File.Delete("Test.sdf"); SqlCeEngine engine = new SqlCeEngine("Data Source = Test.sdf"); engine.CreateDatabase(); conn = new SqlCeConnection("Data Source = Test.sdf"); conn.Open(); SqlCeCommand cmd = conn.CreateCommand(); cmd.CommandText = "CREATE TABLE myTable (col1 INT)"; cmd.ExecuteNonQuery(); cmd.CommandText = "SELECT * FROM myTable"; SqlCeResultSet rs = cmd.ExecuteResultSet(ResultSetOptions.Updatable | ResultSetOptions.Scrollable); SqlCeUpdatableRecord rec = rs.CreateRecord(); // Insert 10 records // for (int i = 0; i < 10; i++) { rec.SetInt32(0, i); rs.Insert(rec); } // Scroll through the results // if (true == rs.ReadFirst()) { MessageBox.Show("col1 = " + rs.GetInt32(0 /*ordinal*/)); } if (true == rs.ReadRelative(5)) { MessageBox.Show("col1 = " + rs.GetInt32(0 /*ordinal*/)); } if (true == rs.ReadLast()) { MessageBox.Show("col1 = " + rs.GetInt32(0 /*ordinal*/)); } if (true == rs.ReadPrevious()) { MessageBox.Show("col1 = " + rs.GetInt32(0 /*ordinal*/)); } if (true == rs.ReadAbsolute(5)) { MessageBox.Show("col1 = " + rs.GetInt32(0 /*ordinal*/)); } } catch (Exception e) { MessageBox.Show(e.Message); } finally { conn.Close(); }