i want to Autogenerate id column in my database table , my code is given below . it is not workin it is giving me Exception as "startIndex Cannot be larger than Length of string , parameter:startIndex ".how should i solve it
Private Sub AutoGenerateNo()
Dim no As String
Try
cmd = New SqlCommand("select count(*) from Academic", conn)
no = cmd.ExecuteScalar
no = no.Substring(2)
no = CInt(no) + 1
If no > 0 And no <= 9 Then
txtSessionId.Text = ("A000" + no)
ElseIf no > 9 And no <= 99 Then
txtSessionId.Text = ("A00" + no)
ElseIf no > 99 And no <= 999 Then
txtSessionId.Text = ("A0" + no)
Else
txtSessionId.Text = ("A" + no)
End If
Catch ex As Exception
MsgBox(ex.Message)
Finally
conn.Close()
End Try
End Sub