0
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
1
Contributor
0
Replies
13
Views
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.