Solved

Finding max value in a dataview column

Posted on 2006-07-02
4
1,986 Views
Last Modified: 2008-02-01
I have a dataview for which I want to find the max value of a column from multiple rows. Is there a method to do this without having to loop through one row at a time?

Thanks.
0
Comment
Question by:Mr_Fulano
4 Comments
 
LVL 10

Accepted Solution

by:
ericwong27 earned 500 total points
Comment Utility

        ' Get the DefaultViewManager of a DataTable.
        Dim view As DataView = DataTable1.DefaultView

        ' Column sorted ascending.
        view.Sort = "NumberColumn DESC"
       
       ' The first row will be the max value
        Debug.WriteLine("Max : " & view(0)("NumberColumn").ToString)
0
 
LVL 9

Expert Comment

by:Naveen Swamy
Comment Utility
0
 
LVL 34

Expert Comment

by:Sancler
Comment Utility
0
 
LVL 8

Expert Comment

by:kaliyugkaarjun
Comment Utility
hi


// C#

// The array rows will contain the row(s) that have the max value of SomeField. There could be more than one if two or more rows have the max value

DataRow[] rows = dataTable.Select("SomeField=Max(SomeField)");



// If you want to bind the result to a control then you can use a DataView

DataView view = new DataView(dataTable);

view.RowFilter = "SomeField=Max(SomeField)";

DataGrid.DataSource = view;

DataGrid.Bind();


this might help u : )






0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Suggested Solutions

Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

771 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

11 Experts available now in Live!

Get 1:1 Help Now