如何操作DataSet

时间:2012-01-31 05:26:09

标签: vb.net winforms

我在操作DataSet时遇到问题,如何在不获取表中的整个记录​​的情况下过滤行。

这是我的代码:

    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

1 个答案:

答案 0 :(得分: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。