?
Solved

VB.Net 2005 DataRow select statement

Posted on 2007-04-09
3
Medium Priority
?
2,087 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 5

Accepted Solution

by:
mytonytiger earned 750 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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
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…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
Suggested Courses

770 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