Geeks With Blogs

News INETA Community Speakers Program
GeeksWithBlogs.net: WTFNext's hosting!

View Stacy Vicknair's profile on LinkedIn


WTF Next? Dev ramblings from a master of nothing.

So it may make sense to you how to fetch information from a DefaultView using RowFilter by binding the view, but what about when you just need to extract a value?

After applying a RowFilter, the first inclination might be to use the DefaultView.Table.Rows to get information that is filtered. Well, that is ultimately wrong. The DefaultView.Table returns the table the view had originated from. The table you get does not have the RowFilter restrictions applied, and therefore returns the whole table. Instead, use the DefaultView.Item(index).Item(columnname) to get the value that really comes from the filtered results. Here's a small snippet to illustrate DefaultView's use as mentioned above:

Public Function GetRate(ByVal id As Integer, ByVal suffix As Integer) As Double
    'fetch rate
    With m_rates.Tables("rates").DefaultView
        'if there are results set rate to the value else 0.0
        .RowFilter = "acn = '" & id.ToString(CultureInfo.InvariantCulture) & "' and sh_sfx = '" & suffix.ToString(CultureInfo.InvariantCulture) & "'"
        If .Count > 0 Then
            Return .Item(0).Item("est_interest_rate")
        Else
            Return 0.0
        End If
    End With
End Function

Again, any comments are welcome on this snippet of code.

 

Technorati Tags: ,,
Posted on Tuesday, December 2, 2008 12:38 PM VB .NET , .NET Tips | Back to top


Comments on this post: .NET Tip: Getting information from DataTable.DefaultView using RowFilter

# re: .NET Tip: Getting information from DataTable.DefaultView using RowFilter
Requesting Gravatar...
You're awesome! This was the fix. Been working on this for months (sorting a XML with DefaultViw and using the data).

Thanks so much!
Left by Richard Jurek on May 14, 2011 7:38 PM

Your comment:
 (will show your gravatar)


Copyright © Stacy Vicknair | Powered by: GeeksWithBlogs.net