2012-01-31 79 views
0

我在操作數據集時遇到問題,我如何過濾行而無需獲取表中的全部記錄。如何操作數據集

這裏是我的代碼:

For j As Integer = 0 To sDataSet.Tables(tran_ar_so_t.Name).Rows.Count - 1 
     Dim nQty, nPrice, nAmount As Double 
     With sDataSet.Tables(tran_ar_so_t.Name) 
      nQty = IIf(.Rows(j).Item("nQty") Is DBNull.Value, 0, .Rows(j).Item("nQty")) : nPrice = IIf(.Rows(j).Item("nPrice") Is DBNull.Value, 0, .Rows(j).Item("nPrice")) 
      ComputeNet(j) 
      nAmount = net * nQty 
      .Rows(j).Item("nAmountDue") = nAmount 
     End With 
    Next 
+0

我不明白這個問題,也不明白代碼是如何與問題相關的。你能舉出一個正在發生的事情和你想要發生的事情的例子嗎? – 2012-01-31 06:45:06

回答

0

也許DataTable.Select()方法可以解決你的問題。檢查這個例子:

Dim filterCondition As String = "nQty > 10" 'A where statement you need 
    Dim filteredRows As DataRow() = sDataSet.Tables(tran_ar_so_t.Name).Select(filterCondition) 

替換「nQty> 0」與您的過濾條件,那麼在filteredRows你會發現只與給定條件匹配的DataRow中。