Solved

VB.Net 2005 DataRow select statement

Posted on 2007-04-09
3
2,039 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
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…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

863 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

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now