Hi here is code snippet used temprarily on button to debug. This works but i wish to use the 2nd snippet.

1st snippet

Dim connString As New SqlConnection

connString.ConnectionString = System.Configuration.ConfigurationManager.ConnectionStrings("sql2008r2_857000_dmcsqlConnectionString").ConnectionString

Dim cmd As New SqlCommand("select TOP 1 no from members ORDER BY no DESC", connString)

Dim reader As SqlDataReader

Dim lastNumber As String

Using (connString)

connString.Open()

reader = cmd.ExecuteReader()

While reader.Read

lastNumber = reader.Item("no")

End While

End Using

Response.Write(lastNumber)

2nd snippet

Dim connString As New SqlConnection

connString.ConnectionString = System.Configuration.ConfigurationManager.ConnectionStrings("sql2008r2_857000_dmcsqlConnectionString").ConnectionString

Dim cmd As New SqlCommand("select max(no) from members ", connString)

Dim reader As SqlDataReader

Dim lastNumber As String

Using (connString)

connString.Open()

reader = cmd.ExecuteReader()

While reader.Read

lastNumber = reader.Item("no")

End While

End Using

Response.Write(lastNumber)

This gives error: System.IndexOutOfRangeException: 'no'

no is a column name which has nvarchar(8) data type and allows nulls

Any help would be welomed