' Nhảy số tự động với VB Net
Private Sub AutoID_Generate()
cmd = New SqlCommand("SELECT MAX(ID) AS [ID] FROM TABLE_AAA", conn)
conn.Open()
Dim myreader = cmd.ExecuteReader
If myreader.Read() Then
If myreader.IsDBNull(0) Then
Dim number As Integer = 1
Dim IDNo As String = number.ToString()
Me.textboxID.Text = IDNo
Else
Dim rd As String = myreader(0).ToString
Dim id As Integer = myreader(0).ToString + 1
Dim NoID As String = id.ToString
Me.textboxID.Text = NoID
End If
conn.Close()
End If
End Sub
Nguồn: Sharecode.vn