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
Get
Set
'Usage
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)
Property Value
Type: System.String
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.
Examples
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();