DbSeekOptions 枚举

指定 Seek 方法将如何对索引进行搜索的选项。

此枚举有一个 FlagsAttribute 属性,允许其成员值按位组合。

命名空间: System.Data.SqlServerCe
程序集: System.Data.SqlServerCe(在 system.data.sqlserverce.dll 中)

语法

声明
<FlagsAttribute> _
Public Enumeration DbSeekOptions
用法
Dim instance As DbSeekOptions
[FlagsAttribute] 
public enum DbSeekOptions
[FlagsAttribute] 
public enum class DbSeekOptions
/** @attribute FlagsAttribute() */ 
public enum DbSeekOptions
FlagsAttribute 
public enum DbSeekOptions

成员

  成员名称 说明
.NET Compact Framework 提供支持 After 按照索引顺序,前进至所包含的值位于查找值之后的第一行。 
.NET Compact Framework 提供支持 AfterEqual 前进至索引中最后一个匹配行。如果没有匹配行,则按照索引顺序,前进至所包含的值位于查找值之后的第一行。 
.NET Compact Framework 提供支持 Before 按照索引顺序,前进至所包含的值位于查找值之前的最后一行。 
.NET Compact Framework 提供支持 BeforeEqual 前进至索引中第一个匹配行。如果没有匹配行,则按照索引顺序,前进至所包含的值位于查找值之前的最后一行。 
.NET Compact Framework 提供支持 FirstEqual 按照索引顺序,前进至索引中第一个匹配行。 
.NET Compact Framework 提供支持 LastEqual 按照索引顺序,前进至索引中最后一个匹配行。  

示例

此示例中为对索引执行 Seek 操作指定了 FirstEqual 选项。

Try
    Dim conn As New SqlCeConnection("Data Source = MyDatabase.sdf")
    conn.Open()

    Dim cmd As SqlCeCommand = conn.CreateCommand()
    cmd.CommandType = CommandType.TableDirect
    cmd.IndexName = "Orders_PK"
    cmd.CommandText = "Orders"

    ' We are interested in orders that match Order ID = 10020
    '
    cmd.SetRange(DbRangeOptions.Match, New Object() {10020}, Nothing)

    Dim reader As SqlCeDataReader = cmd.ExecuteReader(CommandBehavior.Default)

    While reader.Read()
        MessageBox.Show(String.Format("{0} ; {1}", reader("Order ID"), reader("Order Date")))
    End While

    ' Now we are interested in orders with Order ID between (10020, 10050)
    '
    cmd.SetRange(DbRangeOptions.InclusiveStart Or DbRangeOptions.InclusiveEnd, New Object() {10020}, New Object() {10050})

    reader = cmd.ExecuteReader(CommandBehavior.Default)

    ' Now seek to Order ID = 10045
    '
    Dim onRow As Boolean =  reader.Seek(DbSeekOptions.FirstEqual, New Object() {10045})

    ' Now ,the reader will return rows with Order ID >= 10045 <= 10050
    ' because the range was set to (10020, 10050)
    '
    If onRow Then
        While reader.Read()
            MessageBox.Show(String.Format("{0} ; {1}", reader("Order ID"), reader("Order Date")))
        End While
    End If
Catch e As Exception
    MessageBox.Show(e.Message)
End Try
try
{
    SqlCeConnection conn = new SqlCeConnection("Data Source = MyDatabase.sdf");
    conn.Open();

    SqlCeCommand cmd = conn.CreateCommand();
    cmd.CommandType = CommandType.TableDirect;
    cmd.IndexName = "Orders_PK";
    cmd.CommandText = "Orders";

    // We are interested in orders that match Order ID = 10020
    //
    cmd.SetRange(DbRangeOptions.Match, new object[] { 10020 }, null);

    SqlCeDataReader reader = cmd.ExecuteReader(CommandBehavior.Default);

    for (int i = 1; reader.Read(); i++)
    {
        MessageBox.Show(String.Format("{0} ; {1}", reader["Order ID"], reader["Order Date"]));
    }

    // Now we are interested in orders with Order ID between (10020, 10050)
    //
    cmd.SetRange(DbRangeOptions.InclusiveStart | DbRangeOptions.InclusiveEnd,
        new object[] { 10020 }, new object[] { 10050 });

    reader = cmd.ExecuteReader(CommandBehavior.Default);

    // Now seek to Order ID = 10045
    //
    bool onRow = reader.Seek(DbSeekOptions.FirstEqual, new object[] { 10045 });

    // Now ,the reader will return rows with Order ID >= 10045 <= 10050
    // because the range was set to (10020, 10050)
    //
    if (onRow)
    {
        for (int i = 1; reader.Read(); i++)
        {
            MessageBox.Show(String.Format("{0} ; {1}", reader["Order ID"], reader["Order Date"]));
        }
    }
}
catch (Exception e)
{
    MessageBox.Show(e.Message);
}

平台

Windows 98, Windows Server 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

Windows Vista、Microsoft Windows XP SP2 和 Windows Server 2003 SP1 支持 Microsoft .NET Framework 3.0。

版本信息

.NET Framework

受以下版本支持:3.0

.NET Compact Framework

受以下版本支持:2.0、1.0

请参见

参考

System.Data.SqlServerCe 命名空间