This is more a VB problem than ASP.NET. I'm not ever sure this is VB.NET, some of it looks like VBScript. I loathe VB syntax, so code my be slightly off...
You're problem is that you don't know what you've got until you try to get it, e.g, SqlRs.Read(). Also, you will only get a single value. The While is overkill.
vb
nextcode = "00" ' default value
StrSql1 = "SELECT CAST(MAX(GRV_CODE) AS INTEGER)+1 AS CNT FROM GRIEVANCE_DETAILS WHERE EST_CODE='" & DRP_DEPT.SelectedValue & "' "
sqlcmd = New SqlCommand(StrSql1, dbcon)
dbcon.Open()
SqlRs = sqlcmd.ExecuteReader
' we have two options here, 0 or 1 results
If SqlRs.Read() Then
' assuming this actually is a DbDataReader http://msdn.microsoft.com/en-us/library/sy...er_members.aspx
' we've got 1 result
' is it null
If SqlRs.IsDBNull(0) Then
nextcode = Right("00" & SqlRs(0).ToString()), 2)
End If
End If
dbcon.Close()