DataTable.Select 方法 (String)

按照主键顺序(如果没有主键,则按照添加顺序)获取与筛选条件相匹配的所有 DataRow 对象的数组。

[Visual Basic]
Overloads Public Function Select( _
   ByVal filterExpression As String _
) As DataRow()
[C#]
public DataRow[] Select(
   string filterExpression
);
[C++]
public: DataRow* Select(
   String* filterExpression
) [];
[JScript]
public function Select(
   filterExpression : String
) : DataRow[];
参数
filterExpression
要用来筛选行的条件。
返回值

DataRow 对象的数组。

备注

若要创建 filterExpression 参数,请使用与应用于 DataColumn 类的 Expression 用来创建筛选器的属性值相同的规则。

示例

[Visual Basic, C#, C++] 以下示例使用筛选表达式来返回 DataRow 对象的数组。

[Visual Basic] 
Private Sub GetRowsByFilter()
   Dim t As DataTable
   t = DataSet1.Tables("Orders")
   ' Presuming the DataTable has a column named Date.
   Dim strExpr As String
   strExpr = "Date > '1/1/00'"
   Dim foundRows() As DataRow
   ' Use the Select method to find all rows matching the filter.
   foundRows = t.Select(strExpr)
   Dim i As Integer
   ' Print column 0 of each returned row.
   For i = 0 to foundRows.GetUpperBound(0)
      Console.WriteLine(foundRows(i)(0))
   Next i
End Sub

[C#] 
private void GetRowsByFilter(){
   DataTable myTable;
   myTable = DataSet1.Tables["Orders"];
   // Presuming the DataTable has a column named Date.
   string strExpr;
   strExpr = "Date > '1/1/00'";
   DataRow[] foundRows;
   // Use the Select method to find all rows matching the filter.
   foundRows = myTable.Select(strExpr);
   // Print column 0 of each returned row.
   for(int i = 0; i < foundRows.Length; i ++){
      Console.WriteLine(foundRows[i][0]);
   }
}

[C++] 
private:
 void GetRowsByFilter(){
    DataTable* myTable;
    myTable = DataSet1->Tables->Item[S"Orders"];
    // Presuming the DataTable has a column named Date.
    String* strExpr;
    strExpr = S"Date > '1/1/00'";
    DataRow* foundRows[];
    // Use the Select method to find all rows matching the filter.
    foundRows = myTable->Select(strExpr);
    // Print column 0 of each returned row.
    for(int i = 0; i < foundRows->Length; i ++){
       Console::WriteLine(foundRows[i]->Item[0]);
    }
 }

[JScript] 没有可用于 JScript 的示例。若要查看 Visual Basic、C# 或 C++ 示例,请单击页左上角的“语言筛选器”按钮 语言筛选器

要求

平台: Windows 98, Windows NT 4.0, Windows ME, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 系列, .NET Framework 精简版

请参见

DataTable 类 | DataTable 成员 | System.Data 命名空间 | DataTable.Select 重载列表 | CaseSensitive | Expression | DataRow

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值