SqlCeCommand.IndexName Property

Specifies the index to be opened.

Namespace: System.Data.SqlServerCe
Assembly: System.Data.SqlServerCe (in system.data.sqlserverce.dll)

Syntax

'Declaration
Public Property IndexName As String
public string IndexName { get; set; }
public:
property String^ IndexName {
    String^ get ();
    void set (String^ value);
}
/** @property */
public String get_IndexName ()

/** @property */
public void set_IndexName (String value)
public function get IndexName () : String

public function set IndexName (value : String)

Property Value

The name of the index to be opened.

Remarks

IndexName allows the SqlCeDataReader to retrieve rows from a base table based on the order of the rows in the specified index. This allows for ordered retrieval of rows without using a SELECT statement. For example, to retrieve employees based on employee ID, the client could execute SELECT * FROM Employees ORDER BY EmployeeID, but results can be returned more quickly by fetching rows based on an index using the IndexName property. This property can only be used on a command with CommandType set to TableDirect and CommandText set to a valid base table that contains the specified index.

Retrieving rows from an index using the IndexName property will retrieve all rows from a base table in index order. To restrict the rows returned, use SetRange; to look for a specific value in the index, use Seek.

Example

The following example opens a base table and uses an index to quickly retrieve values from the specified range.

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();

Thread Safety

Any public static (Shared in Microsoft Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Platforms

Development Platforms

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
Version Information
.NET Framework and NET Compact Framework
Supported in 3.5
.NET Framework
Supported in 3.0
.NET Compact Framework and .Net Framework
Supported in 2.0

See Also

Reference

SqlCeCommand Class
SqlCeCommand Members
System.Data.SqlServerCe Namespace