当我按下“新建”按钮时,我对该代码有疑问,它没有从数据库中生成递增的数字,所以我想知道这是我正在使用的代码中哪里出了错。
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 <> "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