Share via


SqlCeDataReader.Close Method

SqlCeDataReader 개체를 닫습니다.

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

구문

‘선언
Public Overrides Sub Close
public override void Close ()
public:
virtual void Close () override
public void Close ()
public override function Close ()

주의

연관된 SqlCeConnection을 임의의 용도로 사용하려면 우선 SqlCeDataReader를 사용한 다음 Close 메서드를 명시적으로 호출해야 합니다. 그러나 같은 연결에서 여러 판독기를 만들 수는 있습니다.

다음 예제에서는 SqlCeConnection, SqlCeCommand, SqlCeDataReader 등을 만듭니다. 이 예제에서는 데이터를 읽어서 콘솔에 씁니다. 마지막으로 SqlCeDataReader를 닫은 후 SqlCeConnection을 닫습니다.

Dim conn As SqlCeConnection = Nothing
Dim cmd As SqlCeCommand = Nothing
Dim rdr As SqlCeDataReader = Nothing

Try
    ' Open the connection and create a SQL command
    '
    conn = New SqlCeConnection("Data Source = AdventureWorks.sdf")
    conn.Open()
    
    cmd = New SqlCeCommand("SELECT * FROM DimEmployee", conn)
    
    rdr = cmd.ExecuteReader()
    
    ' Iterate through the results
    '
    While rdr.Read()
        Dim employeeID As Integer = rdr.GetInt32(0) ' or: rdr["EmployeeKey"];
        Dim lastName As String = rdr.GetString(5) ' or: rdr["FirstName"];
    End While
    
    ' Always dispose data readers and commands as soon as practicable
    '
    rdr.Close()
    cmd.Dispose()
Finally
    ' Close the connection when no longer needed
    '
    conn.Close()
End Try
SqlCeConnection conn = null;
SqlCeCommand cmd = null;
SqlCeDataReader rdr = null;

try
{
    // Open the connection and create a SQL command
    //
    conn = new SqlCeConnection("Data Source = AdventureWorks.sdf");
    conn.Open();

    cmd = new SqlCeCommand("SELECT * FROM DimEmployee", conn);

    rdr = cmd.ExecuteReader();

    // Iterate through the results
    //
    while (rdr.Read())
    {
        int employeeID = rdr.GetInt32(0);   // or: rdr["EmployeeKey"];
        string lastName = rdr.GetString(5); // or: rdr["FirstName"];
    }

    // Always dispose data readers and commands as soon as practicable
    //
    rdr.Close();
    cmd.Dispose();
}
finally
{
    // Close the connection when no longer needed
    //
    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에서 지원됨

참고 항목

참조

SqlCeDataReader Class
SqlCeDataReader Members
System.Data.SqlServerCe Namespace