Compartilhar via


Método SqlCeDataReader.Close

Fecha o objeto SqlCeDataReader.

Namespace:  System.Data.SqlServerCe
Assembly:  System.Data.SqlServerCe (em System.Data.SqlServerCe.dll)

Sintaxe

'Declaração
Public Overrides Sub Close
'Uso
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()

Implementa

IDataReader.Close()

Comentários

Para usar a SqlCeConnection associada para qualquer outro fim, primeiro você deve chamar explicitamente o método Close quando terminar de usar o SqlCeDataReader; contudo, você pode criar vários leitores na mesma conexão.

Exemplos

O exemplo a seguir cria uma SqlCeConnection, um SqlCeCommand e um SqlCeDataReader. O exemplo lê os dados e os grava no console. Por fim, o exemplo fecha o SqlCeDataReader e, em seguida, a 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();
}

Consulte também

Referência

SqlCeDataReader Classe

Namespace System.Data.SqlServerCe