Solved

VB.Net 2005 DataRow select statement

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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

706 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

18 Experts available now in Live!

Get 1:1 Help Now