2014-12-27 80 views
0

我的工作在VS 2010 - Vb.Net,在過濾&合併數據集有一個語法澄清過濾和合並數據集在Vb.Net

我的數據集 - DS有23桌。其中,我需要按照一定的標準過濾一張表。

tempDs.Merge(ds.Tables("p_tree_categories").Select("GROUP_CODE <> 'PA.43.948'")) 

上書寫合併語法,

我能看到的只有選定表:tempDs p_tree_categories。我們需要剩餘的22個表以及p_tree_categories的已過濾記錄。

我該如何做到這一點?

回答

1

聽起來像你只有希望過濾的表p_tree_categories行。既然如此,我想:

  1. 生成p_tree_categories的副本只包含您感興趣的行
  2. tempDs刪除現有的p_tree_categories
  3. 將副本合併到tempDs中作爲p_tree_categories

這些步驟可以實現這樣的事:

Dim originalTable As DataTable = tempDs.Tables("p_tree_categories") 

Dim filterView As DataView = New DataView(originalTable) 
filterView.RowFilter = "GROUP_CODE <> 'PA.43.948'" 

Dim filteredTable As DataTable = filterView.ToTable 
filteredTable.TableName = "p_tree_categories" 

' Remove old, add the new. 
tempDs.Tables.Remove(originalTable) 
tempDs.Tables.Add(filteredTable) 
+0

謝謝你,這是一個很大的幫助!我的語法基於你的建議。謝謝 !! – goofyui 2014-12-28 20:54:17