C#的DataTable RowFilter過濾簡介

來源:互聯網
上載者:User

若要形成 RowFilter 值,請指定列的名稱,後跟一個運算子和一個要篩選的值。 該值必須用引號括起來。

//資料集中這列為null或者“”都過濾掉  pds.Tables[0].DefaultView.RowFilter = "欄位名='' or 欄位名 is  null";  //pds.Tables[0].DefaultView.RowFilter = "YHZHBH='00'";  //綁定  this.grid1.DataSource = pds.Tables[0].DefaultView;  DataTable dt = DataView.ToTable();正確的。  DataTable dt = DataView.Table; 擷取的是原來構造DataView的那個原表(沒有過濾之前的那個表)。

重點在於DataView是DateTable相關聯 的一個視圖而已,無論你如何使用RowFilter,DataView雖然被改變,但 DateTable資料不會減少,所以你不要幻想連續使用多個RowFilter 來得到疊加過濾的效果,一個DataView只支援一個RowFilter,你只能使用 not ,and 來串連多個過濾條件。

不過RowFilter不支援不等於(<>、!=、not like),不過如果只是單純的對確定的字串操作,可以用in和not in,資料庫查詢語句則不行。

eg:

dt.DefaultView.RowFilter = "Name in ('zhang')";            dt.DefaultView.RowFilter = "Name not in ('zhang')";            dt.DefaultView.RowFilter = "Name in (select Name from StudentInfo)"; //錯誤

若要形成 RowFilter 值,請指定列的名稱,後跟一個運算子和一個要篩選的值。該值必須用引號括起來。

例如:

"LastName = 'Smith'"  

若要只返回那些具有空值的列,請使用以下運算式:

"Isnull(Col1,'Null Column') = 'Null Column'"

本文URL:http://www.bianceng.cn/Programming/csharp/201410/45574.htm

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.