title: How do i generate new id?
body: <p>I am having problem to this code when i press New button its not generating incremented number from my database so i am wondering where is the wrong in the code this is the code i am using.</p>
  
  <pre><code>Dim getcode As String = "0"
  cmd = New SqlCommand()
  cmd.Connection = cn
  cmd.CommandText = "select top (1) * from TBL_EMPLOYEE order by EmployeeID desc"
  Try
      cn.Open()
      Dim reader As SqlDataReader = cmd.ExecuteReader(CommandBehavior.SingleRow)
      If (reader.HasRows = True) Then
          While reader.Read
              getcode = (reader.GetString(reader.GetOrdinal("EmployeeID")))
          End While
      End If
      cn.Close()
      reader.Close()
  Catch ex As Exception
  End Try
  If (getcode = "0") Then
      Me.txtEMPID.Text = "EMPID-000001"
  ElseIf (getcode &lt;&gt; "0") Then
      Dim totalcodewithoutlabel As String = getcode.Count - 4
      Dim oldnum As String = getcode.Substring(getcode.Length - totalcodewithoutlabel)
      Me.txtEMPID.Text = "EMPID-" + Format(oldnum + 1, "000000").ToString
  End If
  </code></pre>