Solved

Finding max value in a dataview column

Posted on 2006-07-02
4
2,225 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
[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
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 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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

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 …
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

705 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