Share via


SqlCeDataReader.Close 메서드

SqlCeDataReader 개체를 닫습니다.

네임스페이스:  System.Data.SqlServerCe
어셈블리:  System.Data.SqlServerCe(System.Data.SqlServerCe.dll)

구문

‘선언
Public Overrides Sub Close
‘사용 방법
Dim instance As SqlCeDataReader

instance.Close()
public override void Close()
public:
virtual void Close() override
abstract Close : unit -> unit 
override Close : unit -> unit 
public override function Close()

구현

IDataReader.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();
}

참고 항목

참조

SqlCeDataReader 클래스

System.Data.SqlServerCe 네임스페이스