按照主键顺序(如果没有主键,则按照添加顺序)获取与筛选条件相匹配的所有 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