• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2123
  • Last Modified:

VB.Net 2005 DataRow select statement

Good morning,
 
I had some help on this site about using a Compute paramter on a DataRow statement to retrieve data for my funciton as follows.  decIT3 is a variable I'm returning via a function.

decIT3 = dtSales_Budget.Compute("Sum(Amount)", "Year = " & yearValue & " AND Period = " & intPeriod & " AND Type = 'IT'")

I'd like to do similar with a non-aggregate function, as in with selecting data this way without sum, avg, max...whatever.  I'm looking for a way to select a value from a certain row meeting my criteria.

Is there a way to do so?

Thanks,
JMO9966



0
JMO9966
Asked:
JMO9966
  • 2
1 Solution
 
mytonytigerCommented:
There are two basic ways to select a specific row.
DT = DataTable with data
1) If you have a key column, you can do this

DT.Rows.find(key as object)
'The key is the value of the primary key

2)
DT.Select (FilterExpression as string)
'Overloads provide parameters for sorting, and specifying record states


Hope that helps.
0
 
JMO9966Author Commented:
Thanks,
 
Would you happen to have example syntax?  

I'm typically trying to access a certain column or columns value(s) for a specific DataRow with two or three filter expressions needed  to get to the correct row in the DataTable.

I used to loop through my DataTables but this way seems a lot quicker if I can fine-tune the find or select methods.

Thanks again,
JMO9966

0
 
mytonytigerCommented:
Sorry I didn't get an example to you. I never got the email notification that you had replied though.



Example 1:

        Dim dt As New DataTable
        'Fill data table with data
        Dim r As DataRow
        'find the row with the primary key = 27
        r = dt.Rows.Find("27")


Example 2:

        Dim dt As New DataTable
        'Fill data table with data

        Dim rows As DataRow()
        'Return all rows in which the Date field is greater than Jan 1st, 2000
        rows = dt.Select("Date > '1/1/2000'")

        For Each dr As DataRow In rows
            'do what you need to do
        Next


0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now