SqlCeResultSet.ReadRelative Method
Visual Studio 2010
Moves the reader the specified amount from the current position.
Namespace: System.Data.SqlServerCe
Assembly: System.Data.SqlServerCe (in System.Data.SqlServerCe.dll)
Parameters
- position
- Type: System.Int32
The number of positions to move the reader.
The following example creates a ResultSet object and then calls several methods, including ReadRelative.
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(); }
