1. 程式人生 > >DataTable.Select 方法

DataTable.Select 方法

DataTable.Select方法返回獲取所有DataRow物件的陣列。Select()有四個過載方法.

名稱 說明
公共方法由 XNA Framework 提供支援 Select () 獲取所有 DataRow 物件的陣列。
公共方法由 XNA Framework 提供支援 Select(String) 按照主鍵順序(如果沒有主鍵,則按照新增順序)獲取與篩選條件相匹配的所有 DataRow 物件的陣列。
公共方法由 XNA Framework 提供支援 Select(String, String) 獲取按照指定的排序順序且與篩選條件相匹配的所有 DataRow  物件的陣列。
公共方法由 XNA Framework 提供支援 Select(String, String, DataViewRowState) 獲取與排序順序中的篩選器以及指定的狀態相匹配的所有 DataRow  物件的陣列。

1.Select()示例:

 private void GetRows()
{
    // Get the DataTable of a DataSet.
    DataTable table = DataSet1.Tables["Suppliers"];
    DataRow[] rows = table.Select();

    // Print the value one column of each DataRow.
    for(int i = 0; i < rows.Length ; i++)
    {
        Console.WriteLine(rows[i]["CompanyName"

]);
    }
}

2.Select(string filterExpression)示例:

 private void GetRowsByFilter()
{
    DataTable table = DataSet1.Tables["Orders"];
    // Presuming the DataTable has a column named Date.
    string expression;
    expression = "Date > #1/1/00#";
    DataRow[] foundRows;

    // Use the Select method to find all rows matching the filter.


    foundRows = table.Select(expression);

    // Print column 0 of each returned row.
    for(int i = 0; i < foundRows.Length; i ++)
    {
        Console.WriteLine(foundRows[i][0]);
    }
}

3.Select(string filterExpression,string sort)示例:

    private void GetRowsByFilter()
   {
       DataTable table = DataSet1.Tables["Orders"];

       // Presuming the DataTable has a column named Date.
       string expression = "Date > '1/1/00'";

       // Sort descending by column named CompanyName.
       string sortOrder = "CompanyName DESC";
       DataRow[] foundRows;

       // Use the Select method to find all rows matching the filter.
       foundRows = table.Select(expression, sortOrder);

      // Print column 0 of each returned row.
       for(int i = 0; i < foundRows.Length; i ++)
       {
           Console.WriteLine(foundRows[i][0]);
       }
   }
4.Select(string filterExpression,string sort, DataViewRowState recordStates)示例:

    private staticvoid GetRowsByFilter()
    {
        DataTable customerTable =
new DataTable("Customers");
       
// Add columns
        customerTable.Columns.Add("id", typeof(int));
        customerTable.Columns.Add(
"name", typeof(string));

       
// Set PrimaryKey
        customerTable.Columns[ "id" ].Unique = true;
        customerTable.PrimaryKey =
new DataColumn[]
            { customerTable.Columns[
"id"] };

       
// Add ten rows
for(int id=1; id<=10; id++)
        {
            customerTable.Rows.Add(
               
new object[] { id, string.Format("customer{0}", id) });
        }
        customerTable.AcceptChanges();

       
// Add another ten rows
for(int id=11; id<=20; id++)

        {

            customerTable.Rows.Add( new object[] { id, string.Format("customer{0}", id) });
        }

       
string expression;
       
string sortOrder;
   
        expression =
"id > 5";
       
// Sort descending by column named CompanyName.
        sortOrder = "name DESC";
       
// Use the Select method to find all rows matching the filter.
        DataRow[] foundRows =
            customerTable.Select(expression, sortOrder,
            DataViewRowState.Added);
   
        PrintRows(foundRows,
"filtered rows");

        foundRows = customerTable.Select();
        PrintRows(foundRows,
"all rows");
    }

   
private staticvoid PrintRows(DataRow[] rows, string label)
    {
        Console.WriteLine(
"/n{0}", label);
       
if(rows.Length <= 0)
        {
            Console.WriteLine(
"no rows found");
           
return;
        }
       
foreach(DataRow row in rows)
        {
           
foreach(DataColumn column in row.Table.Columns)
            {
                Console.Write(
"/table {0}", row[column]);
            }
            Console.WriteLine();
        }
    }

相關推薦

DataTable.Select 方法

DataTable.Select方法返回獲取所有DataRow物件的陣列。Select()有四個過載方法. 名稱 說明 Select () 獲取所有 DataRow 物件的陣列。 Select(String) 按照主鍵順序(如果沒有主鍵,則按照新增順序)獲取與篩選條件

取代DataTable Select方法 並動態拼接Lambda表達式

lamda tails lam 必須 object .com rime row tlist 原來的程序裏面,有這樣一段代碼 var parentFilterString = string.Empty; p

C# DatatableSelect方法

DataTable是我們在進行開發時經常用到的一個類,並且經常需要對DataTable中的資料進行篩選等操作,下面就介紹一下Datatable中經常用到的一個方法——Select,微軟提供了四個函式的過載,分別是 Select() Select(string filte

DataTable 使用Select方法查詢並排序,以及【拼接轉義符的問題】

關於DataTable 裡面用 /轉義符拼接的問題 //這種寫法表面上是正確,實現上在執行時呼叫Select方法實行查詢會報錯 string str = resetstrWhere + "\"" + "," + "\"" + dataQuery.DefaultOrderByClause; table =

ASP.NET操作DataTable各種方法

[] ret 增加 另一個 turn 根據 好的 asp.net 默認 轉:http://www.cnblogs.com/isking/p/6178268.html http://www.cnblogs.com/sntetwt/p/3496477.html public

BeautifulSoup select方法

圖書 電動車 收藏 spider pri chan 文件 process 保健 1 html = """ 2 <html><head><title>The Dormouse‘s story</title></hea

匿名類型與Select方法實現自定義對象插入局部表結構中

aso 直接 菜單 ember new order ber 構建 als 在提取局部表結構數據時,通過Select選取需要的字段,如下句,此時其實產生了一個不用於_menuMan的原新數據類型new { c.SYS_COMMANDS_ID,c.TXT_COMMANDTITL

BeautifulSoup 使用select方法詳解(通過標簽名,類名, id,組合,屬性查找)

chrome red 例如 ttl app user encode and 定位 import requestsfrom bs4 import BeautifulSoupblslib="html5lib"user_agent="Mozilla/5.0 (Macintosh;

BeautifulSoup中的select方法

title -- span sel 不能 com class spa alt 在寫css時,標簽名不加任何修飾,類名前加點,id名前加 #,我們可以用類似的方法來篩選元素,用到的方法是soup.select(),返回類型是list。 (1).通過標簽名查找 print(

DataTable中執行DataTable.Select("條件"),

for 限定 str tail lec sql語言 tex from 字符 1.在DataTable中執行DataTable.Select("條件")返回DataTable; // <summary> // 執行DataTable中的查詢返回新的DataTabl

關於Select方法的使用

//for 迴圈將陣列展開再進行轉換 object[] Obj = new object[9]; GameObject[] Gobj=new GameObject[9]; for (int i = 0; i < Obj.Length; i+

BS4 select 方法取值

# -*- coding: utf-8 -*- import requests from bs4 import BeautifulSoup html=requests.get('http://vip.stock.finance.sina.com.cn/corp/view/vCB_Bullet

ASP.NET操作DataTable各種方法總結(給Datatable新增行列、DataTable選擇排序等)

  using System; using System.Collections.Generic; using System.Data; using System.Text; namespace Gzcms.Common { public cl

Python BeautifulSoup4 select方法執行css選擇器

初識爬蟲,使用urllib結合強大的BeautifulSoup簡單寫了下程式碼。看參考書上主要講解了find方法的使用,但發現其是還支援css選擇器語法選擇,於是試驗了一下。 環境為:ubuntu12.04 + pycharm2017.1.3 + python

http協議,阻塞IO,非阻塞IO,IO多路複用,位運算,select方法

HTTP請求   Request 請求格式: 請求行       GET          /         HTTP/1.1  請求種類  

EFCore擴充套件Select方法(自動對映自定義實體)

EFCore擴充套件Select方法(自動對映自定義實體)  通常用操作資料庫的時候查詢返回的欄位是跟 我們的定義的實體是不一致的,所以往往針對UI或者介面層建立大量的Model, 而且需要手動對應欄位,非常繁瑣。 本文將通過表示式樹解決這些重複的過程。   

DataTable select() 的使用;DataTabel中distinct用法去重複的的欄位或者記錄 .

DataTabel中distinct 在.NET Framework2.0中,選擇DataTable等資料來源中的唯一值(類似SQL中Distinct的返回結果)非常簡單,如下即可: DataTable d = dataSetName.dataTableName.Defa

C# DataTable.Select() 篩選資料

有時候我們需要對資料表進行篩選,微軟為我們封裝了一個公共方法, DataTable.Select(),其用法如下: Select() Select(string filterExpression) Select(string filterExpression, 

c# DataTable select 過濾返回新DataTable

        DataRow[] dr = dt.Select(“col='XXXX'”);//條件:就是欄位名='某某'         /// 執行DataTable中的查詢返回新的DataTable         /// </summary>     

C# DataTable使用方法詳解

  在專案中常常常使用到DataTable,假設DataTable使用得當,不僅能使程式簡潔有用,並且可以提高效能,達到事半功倍的效果,現對DataTable的使用技巧進行一下總結。 1、新增引用 ? 1 using System.D