As what I have understand in your problem, you are trying to get the biggest number from the field "mrn_no".
Then in your code maxrows = ds.Tables("mr_head").Rows.count... You know, this code will count the number of rows found in your query and not the max number from "mrn_no".
So if you want to get the max("mrn_no") to be displayed, this is the way you shoud do it: I prefer to use DataTable instead of DataSet, but you can use any.
Dim dT as New DataTable
Dim da As New OleDb.OleDbDataAdapter
Dim sql As String = "select max(mrn_no) from mr_head"
da = New OleDb.OleDbDataAdapter(sql, conn)
'this is a fragment of the code, you should be able to understand this
da.Fill(dT)
'This code will return what you are looking for
maxvalue = dT.Rows(0)("mrn_no")
'This code will return the number of rows found in your query
maxrow = dT.Rows.count - 1
This should solve your problem....
Hope this helps...