Results 1 to 2 of 2

Thread: To get the max value from a datacolumn

  1. #1

    Thread Starter
    Addicted Member samkud's Avatar
    Join Date
    Oct 2001
    Location
    India
    Posts
    171

    To get the max value from a datacolumn

    Hi Guys,

    Is there any way by which I can get the max value from a particular column of a datatable. Please let me know.

    Regards,

    Samir.

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: To get the max value from a datacolumn

    Are you talking about by SQL from a database or in an existing DataTable? If you mean froma database then it would just be:
    Code:
    SELECT MAX(ColumnName) FROM TableName
    You would assign that to the CommandText of the appropriate type of command object and call ExecuteScalar. If you mean from an existing DataTable then you could create a DataView, or use the DefaultView, and set the Sort property to:
    Code:
    ColumnName DESC
    and then get the value from that column of the first row in the view.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width