This documentation is archived and is not being maintained.

SqlCeCommand.IndexName Property

Specifies the index to be opened.

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

public string IndexName { get; set; 
/** @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.

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 reading from an index using the IndexName property. This property can only be used on a command with CommandType set to BaseTable 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.

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

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

  • Full trust for the immediate caller. This member cannot be used by partially trusted code. For more information, see .

Windows CE, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows XP Professional x64 Edition, Windows XP SP2

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.

.NET Compact Framework

Supported in: 2.0, 1.0
Show: