Solved

Finding max value in a dataview column

Posted on 2006-07-02
4
2,153 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
ID: 17029023

        ' 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
ID: 17029226
0
 
LVL 34

Expert Comment

by:Sancler
ID: 17029854
0
 
LVL 8

Expert Comment

by:kaliyugkaarjun
ID: 17041056
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Help with exporting to excel 4 45
VB.NET 2008 - SQL Timeout 9 50
Generate Numbers in JQuery file 11 72
Optimize the query 5 52
Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

749 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