Share via


DbRangeOptions 枚举

在指定要查找的索引范围时,应指定 SetRange 方法使用的选项。

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

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

语法

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

成员

  成员名称 说明
.NET Compact Framework 提供支持 Default 相当于同时设置 InclusiveStartInclusiveEnd 标志。 
.NET Compact Framework 提供支持 ExcludeNulls 从范围中排除 空引用(在 Visual Basic 中为 Nothing) 值。 
.NET Compact Framework 提供支持 ExclusiveEnd 从范围中排除 endData 值。 
.NET Compact Framework 提供支持 ExclusiveStart 从范围中排除 startData 值。 
.NET Compact Framework 提供支持 InclusiveEnd 在范围中内包含 endData 值。 
.NET Compact Framework 提供支持 InclusiveStart 在范围中内包含 startData 值。 
.NET Compact Framework 提供支持 Match 指定索引值与 startData 值相匹配的范围。在使用 Match 选项时,endData 必须设置为 空引用(在 Visual Basic 中为 Nothing)。 
.NET Compact Framework 提供支持 Prefix 指定一个范围,在该范围中让索引值从 startData 值开始。在使用 Prefix 选项时,endData 必须设置为 空引用(在 Visual Basic 中为 Nothing)。 

备注

在指定 Match 或 Prefix 选项时,endData 值必须为 空引用(在 Visual Basic 中为 Nothing)。

不能合并 Match 和 ExcludeNulls 选项。

示例

在此示例中,在调用 SetRange 方法时,对索引执行的 Seek 操作的范围选项被指定为 InclusiveStart 或 InclusiveEnd。

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 命名空间