Compartir a través de


SqlCeCommand.IndexName Propiedad

Especifica el índice que se va a abrir.

Espacio de nombres:  System.Data.SqlServerCe
Ensamblado:  System.Data.SqlServerCe (en System.Data.SqlServerCe.dll)

Sintaxis

'Declaración
Public Property IndexName As String
    Get
    Set
'Uso
Dim instance As SqlCeCommand
Dim value As String

value = instance.IndexName

instance.IndexName = value
public string IndexName { get; set; }
public:
property String^ IndexName {
    String^ get ();
    void set (String^ value);
}
member IndexName : string with get, set
function get IndexName () : String
function set IndexName (value : String)

Valor de la propiedad

Tipo: System.String
Nombre del índice que se va a abrir.

Comentarios

IndexName permite que SqlCeDataReader recupere filas de una tabla base basándose en el orden de las filas del índice especificado. De esta forma, las filas se recuperan en orden sin tener que utilizar una instrucción SELECT. Por ejemplo, para recuperar empleados por su Id. de empleado, el cliente puede ejecutar SELECT * FROM Employees ORDER BY EmployeeID, pero la operación puede ser más rápida si se obtienen filas en función de un índice utilizando la propiedad IndexName. Esta propiedad sólo puede utilizarse en un comando con CommandType establecido en TableDirect y CommandText establecido en una tabla base válida que contenga el índice especificado.

La recuperación de filas a partir de un índice mediante la propiedad IndexName recuperará todas las filas de la tabla base en el orden del índice. Para restringir las filas devueltas, utilice SetRange; para buscar un valor específico en el índice, utilice Seek.

Ejemplos

En el ejemplo siguiente se abre una tabla base y se utiliza un índice para recuperar rápidamente los valores del intervalo especificado.

Dim cmd As SqlCeCommand = conn.CreateCommand()
cmd.CommandType = CommandType.TableDirect

' This is the name of the base table 
'
cmd.CommandText = "Orders"

'Assume: Index contains three columns [int, datetime, money]
'
cmd.IndexName = "SomeIndex"

Dim start(2) As Object
Dim [end](0) As Object

start(0) = 1
start(1) = New SqlDateTime(1996, 1, 1)
start(2) = New SqlMoney(10.0)

[end](0) = 5

cmd.SetRange(DbRangeOptions.InclusiveStart Or DbRangeOptions.InclusiveEnd, start, [end])

Dim rdr As SqlCeDataReader = cmd.ExecuteReader()
rdr.Seek(DbSeekOptions.AfterEqual, 1, New SqlDateTime(1997, 1, 1), New SqlMoney(10.5))

While rdr.Read()
    ' Read data the usual way 
    '
End While
rdr.Close()
SqlCeCommand cmd = conn.CreateCommand();
cmd.CommandType = CommandType.TableDirect;

// This is the name of the base table 
//
cmd.CommandText = "Orders";

//Assume: Index contains three columns [int, datetime, money]
//
cmd.IndexName = "SomeIndex";

object[] start = new object[3];
object[] end = new object[1];

start[0] = 1;
start[1] = new SqlDateTime(1996, 1, 1);
start[2] = new SqlMoney(10.00);

end[0] = 5;

cmd.SetRange(DbRangeOptions.InclusiveStart | DbRangeOptions.InclusiveEnd, start, end);

SqlCeDataReader rdr = cmd.ExecuteReader();
rdr.Seek(DbSeekOptions.AfterEqual, 1, new SqlDateTime(1997, 1, 1), new SqlMoney(10.50));

while (rdr.Read())
{
    // Read data the usual way 
    //
}
rdr.Close();

Vea también

Referencia

SqlCeCommand Clase

Espacio de nombres System.Data.SqlServerCe