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
'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);
}
/** @property */
public String get_IndexName ()
/** @property */
public void set_IndexName (String value)
public function get IndexName () : String
public function set IndexName (value : String)
Not applicable.
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 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.
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();
Platforms
Windows CE, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows XP Professional x64 Edition, Windows XP SP2
The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.
Version Information
.NET Framework
Supported in: 3.0
.NET Compact Framework
Supported in: 2.0, 1.0
See Also
Reference
SqlCeCommand Class
SqlCeCommand Members
System.Data.SqlServerCe Namespace