Code อันนี้เป็นการเรียก ID ล่าสุดแล้วนำไป +1 ตามที่คุณ vampippo ต้องการนะครับ(VB.NET)
Private Sub AutoGenerateDrawID()
Dim sqlTmp As String = ""
Dim comTmp As SqlCommand = New SqlCommand
Dim drDraw As SqlDataReader
Dim tmpDrawID As String = ""
Dim FirstID As Integer = 0
Dim LastID As Integer = 0
Dim ThisYear As Integer
ThisYear = Date.Now.Year
sqlTmp = "SELECT TOP 1 DrawID FROM Draw "
sqlTmp &= " ORDER BY DrawID DESC"
Dim strConn As String
strConn = DBConnString.strConn
Conn = New SqlConnection()
With Conn
If .State = ConnectionState.Open Then .Close()
.ConnectionString = strConn
.Open()
End With
Try
With comTmp
.CommandType = CommandType.Text
.CommandText = sqlTmp
.Connection = Conn
drDraw = .ExecuteReader()
End With
drDraw.Read()
tmpDrawID = CStr(drDraw.Item("DrawID"))
FirstID = CInt(StringFromLeft(tmpDrawID, 1))
LastID = CInt(StringFromRight(tmpDrawID, 7))
LastID = LastID + 1
LastDrawID = FirstID.ToString("0") & LastID.ToString("0000000")
Catch
LastDrawID = "00000001"
End Try
lblid.Text = LastDrawID
drDraw.Close()
End Sub