Solved

VB.Net 2005 DataRow select statement

Posted on 2007-04-09
3
2,047 Views
Last Modified: 2008-01-09
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
Comment
Question by:JMO9966
  • 2
3 Comments
 
LVL 5

Accepted Solution

by:
mytonytiger earned 250 total points
ID: 18876195
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
 

Author Comment

by:JMO9966
ID: 18891831
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
 
LVL 5

Expert Comment

by:mytonytiger
ID: 18904887
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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

776 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question