Dim conn As New OleDb.OleDbConnection
        Dim dbprovider As String
        Dim dbsource As String
        Dim ds As New DataSet
        Dim da As New OleDb.OleDbDataAdapter
        Dim sql As String
        Dim maxrows As Integer
        dbprovider = "PROVIDER=Microsoft.Jet.OLEDB.4.0;"
        dbsource = "Data Source = d:\sprrg\scm\scm\sprrg.mdb"
        conn.ConnectionString = dbprovider & dbsource
        conn.Open()
        sql = "select max(mrn_no) from mr_head"
        da = New OleDb.OleDbDataAdapter(sql, conn)
        da.Fill(ds, "mr_head")
        maxrows = ds.Tables("mr_head").Rows.Count

I want to find out the max number from one table and when i execute this query i am getting the error as No value given for one or more required parameters.

Kindly help me...

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...

If you want to get the max value from one column you don't need to bother with the dataTable or dataSet at all. SELECT MAX() returns the max value so just parse the result from the executeScalar() command.
But, beside that, seeing you aren't using parameters check your column names are correct.

Dim conn As New OleDb.OleDbConnection
        Dim dbprovider As String
        Dim dbsource As String
        Dim ds As New DataSet
        Dim da As New OleDb.OleDbDataAdapter
        Dim sql As String
        dbprovider = "PROVIDER=Microsoft.Jet.OLEDB.4.0;"
        dbsource = "Data Source = d:\sprrg\scm\scm\sprrg.mdb"
        conn.ConnectionString = dbprovider & dbsource
        conn.Open()
        sql = "select max(mr_no) from mr_head"
        da = New OleDb.OleDbDataAdapter(sql, conn)
        da.Fill(ds, "mr_head")
        'MsgBox(ds.Tables("mr_head").Rows(0).Item(0))
        Dim mrn_no As Integer
        mrn_no = ds.Tables("mr_head").Rows(0).Item(0)

        MsgBox("Next MRN No will be " & mrn_no + 1)

After some R&D i've find out the soultion... Thanks for everybody...

This question has already been answered. Start a new discussion instead.