Click here to Skip to main content
15,896,063 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi how can i Take a max value of a field of data base?
Posted

Probably using ADO.NET[^]. An Object Implementing IDbCommand[^] can take your query. In case of Access the OleDbCommand[^].
VB
Dim cmd As New OleDbCommand("SELECT MAX(MyColumn) FROM MyTable", connection) ' connection is an IDbConnection Object, OleDbConnection here.
Dim maxValue As Integer = cmd.ExecuteScalar

In case you're using an ORM like LINQ to XML or Entity Framework LINQ would do the trick.
VB
Dim i As Integer = context.MyTable.Max(Function(o) o.MyValue)

Hope it helps :)
 
Share this answer
 
Comments
synctor 18-Nov-11 5:03am    
thank you
Sander Rossel 18-Nov-11 6:53am    
No problem :)
Mehdi Gholam 18-Nov-11 5:08am    
my 5!
Sander Rossel 18-Nov-11 6:53am    
Thanks Mehdi :)
Use the MAX function (assuming you want the columnname from the tablename table):
SQL
select MAX(columnname) from [tablename]
 
Share this answer
 
Comments
synctor 18-Nov-11 4:59am    
how can i take that value ?
Mehdi Gholam 18-Nov-11 5:08am    
Use ExecuteScalar.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900