Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
AutoGenerateID()
End Sub
Private Sub AutoGenerateID()
Dim Conn As New System.Data.SqlClient.SqlConnection("Data Source=.\sqlexpress;Initial Catalog=Northwind;Integrated Security=True")
Dim sqlTmp As String = ""
Dim comTmp As New SqlClient.SqlCommand
Dim drTmp As SqlClient.SqlDataReader
Dim tmpMemberID As Integer = 0
sqlTmp = "SELECT TOP 1 EmployeeID FROM Employees ORDER BY CAST(EmployeeID AS int) DESC"
If (Conn.State = ConnectionState.Closed) Then
Conn.Open()
End If
Try
With comTmp
.CommandType = CommandType.Text
.CommandText = sqlTmp
.Connection = Conn
drTmp = .ExecuteReader()
drTmp.Read()
tmpMemberID = CInt(drTmp.Item("EmployeeID"))
tmpMemberID = tmpMemberID + 1
TextBox1.Text = strDate & "-" & tmpMemberID.ToString("00000") '// 08-xxxxx
End With
Catch
TextBox1.Text = strDate & "-" & "00001" '// 08-00001
End Try
'drTmp.Close()
End Sub