Share via


SqlCeResultSet.ReadPrevious Method

현재 레코드 이전의 레코드에 판독기를 배치합니다.

네임스페이스: System.Data.SqlServerCe
어셈블리: System.Data.SqlServerCe(system.data.sqlserverce.dll에 있음)

구문

‘선언
Public Function ReadPrevious As Boolean
public bool ReadPrevious ()
public:
bool ReadPrevious ()
public boolean ReadPrevious ()
public function ReadPrevious () : boolean

반환 값

작업이 성공하면 true이고 그렇지 않으면 false입니다.

다음 예제에서는 ResultSet 개체를 만든 다음 ReadPrevious 등을 포함한 여러 메서드를 호출합니다.

Dim conn As SqlCeConnection = Nothing

Try
    File.Delete("Test.sdf")

    Dim engine As New SqlCeEngine("Data Source = Test.sdf")
    engine.CreateDatabase()

    conn = New SqlCeConnection("Data Source = Test.sdf")
    conn.Open()

    Dim cmd As SqlCeCommand = conn.CreateCommand()
    cmd.CommandText = "CREATE TABLE myTable (col1 INT)"
    cmd.ExecuteNonQuery()

    cmd.CommandText = "SELECT * FROM myTable"

    Dim rs As SqlCeResultSet = cmd.ExecuteResultSet(ResultSetOptions.Updatable Or ResultSetOptions.Scrollable)

    Dim rec As SqlCeUpdatableRecord = rs.CreateRecord()

    ' Insert 10 records
    '
    Dim i As Integer
    For i = 0 To 9
        rec.SetInt32(0, i)
        rs.Insert(rec)
    Next i

    ' Scroll through the results
    '
    If True = rs.ReadFirst() Then
        MessageBox.Show("col1 = " & rs.GetInt32(0)) 'ordinal
    End If

    If True = rs.ReadRelative(5) Then
        MessageBox.Show("col1 = " & rs.GetInt32(0)) 'ordinal
    End If

    If True = rs.ReadLast() Then
        MessageBox.Show("col1 = " & rs.GetInt32(0)) 'ordinal
    End If

    If True = rs.ReadPrevious() Then
        MessageBox.Show("col1 = " & rs.GetInt32(0)) 'ordinal
    End If

    If True = rs.ReadAbsolute(5) Then
        MessageBox.Show("col1 = " & rs.GetInt32(0)) 'ordinal
    End If
Catch e As Exception
    MessageBox.Show(e.Message)
Finally
    conn.Close()
End Try
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();
}

스레드 보안

이 유형의 모든 public static(Microsoft Visual Basic의 경우 공유) 멤버는 스레드로부터 안전합니다. 인스턴스 멤버는 스레드로부터의 안전성이 보장되지 않습니다.

플랫폼

개발 플랫폼

Windows Vista, Windows Mobile 5.0, Windows XP Professional with Service Pack 2 (SP2), Windows Server 2003, Windows Mobile 2003 for Pocket PC, Windows CE 5.0
버전 정보
.NET Framework 및 NET Compact Framework
3.5에서 지원됨
.NET Framework
3.0에서 지원됨
.NET Compact Framework 및 .Net Framework
2.0에서 지원됨

참고 항목

참조

SqlCeResultSet Class
SqlCeResultSet Members
System.Data.SqlServerCe Namespace