Private Sub AutoGenerateID()
Dim sqlTmp As String = ""
Dim comTmp As New SqlClient.SqlCommand
Dim drTmp As SqlClient.SqlDataReader
Dim tmpMemberID As Integer = 0
sqlTmp = "SELECT TOP 1 OrderID FROM OrderBuy ORDER BY CAST(OrderID AS int) DESC"
If (DbConn.State = ConnectionState.Closed) Then
DbConn.Open()
End If
Try
With comTmp
.CommandType = CommandType.Text
.CommandText = sqlTmp
.Connection = DbConn
drTmp = .ExecuteReader()
drTmp.Read()
orderID.Text = CInt(drTmp.Item("OrderID") + 1)
tmpMemberID = CInt(drTmp.Item("OrderID"))
tmpMemberID = tmpMemberID + 1
orderID.Text = strDate & strMonth & "-" & tmpMemberID.ToString("0000")
End With
Catch
orderID.Text = strDate & strMonth & "-" & "0001" '5409-0001
DbConn.Close()
End Try
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
AutoGenerateID()
End Sub