Sub GenID()
Dim id As Integer = 0
Dim str As String = ""
sql = "select top 1 PK from ชื่อตาราง order by PK DESC"
Da = New SqlDataAdapter(Sql, cn)
DtID = New DataTable
Da.Fill(DtID)
If DtID.Rows.Count > 0 Then
str = DtID.Rows(0).Item("BloodID")
id = str.Substring(1, 2)
id = id + 1
LblID.Text = "B" & id.ToString("00")
Else
LblID.Text = "B01" ----> รหัสเริ่มต้น
End If
Sub autoid()
Dim tmpautoid As Integer = 0
Dim sqlauto As String
sqlauto = "SELECT * FROM Table Order by Field ASC "
DC.CommandType = CommandType.Text
DC.CommandText = sqlauto
DC.Connection = CONN
DA = New OleDbDataAdapter(DC)
DS1.Clear()
DA.Fill(DS1, "number")
tmpautoid = (DS1.Tables("number").Rows.Count) + 1
txt_Id.Text = Format("NameAuto" + tmpautoid.ToString("NumberAuto"))
End Sub