SqlCeDataReader.Close Método
Cierra el objeto SqlCeDataReader.
Espacio de nombres: System.Data.SqlServerCe
Ensamblado: System.Data.SqlServerCe (en System.Data.SqlServerCe.dll)
Sintaxis
'Declaración
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
Comentarios
Para utilizar el objeto SqlCeConnection asociado con cualquier otra finalidad, deberá llamar primero al método Close explícitamente cuando termine de utilizar SqlCeDataReader; no obstante, puede crear varios lectores en la misma conexión.
Ejemplos
En el siguiente ejemplo, se crean una conexión SqlCeConnection, un objeto SqlCeCommand y un SqlCeDataReader. En el ejemplo se leen los datos y se escriben en la consola. Por último, en el ejemplo se cierra SqlCeDataReader y, a continuación, 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();
}