Export (0) Print
Expand All

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 Value

Type: System.String
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 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.

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


Show:
© 2014 Microsoft