Dim s As String = ""
s = "Select Top 1 id_sup From suppliers Order By id_sup DESC"
Dim da As New SqlDataAdapter(s, cn)
Dim ds As New DataSet
da.Fill(ds, "id_sup")
Dim ny As String = Now.Year + 543
Dim y As String = ny.Substring(2, 2)
Dim m As String = Now.Month.ToString("-")
Dim newid As String = ""
With ds.Tables("id_sup")
If .Rows.Count = 0 Then
newid = y & m & "001"
TextBox2.Text = newid
Exit Sub
End If
Dim oldid, Lid, mid, Rid As String
oldid = .Rows(0).Item(0).ToString
Lid = oldid.Substring(0, 2)
mid = oldid.Substring(2, 2)
Rid = oldid.Substring(3, 3)
If y = Lid Then
If m = mid Then
newid = y & m & (CInt(Rid) + 1).ToString("000")
Else
newid = y & m & "001"
End If
Else
newid = y & m & "001"
End If
TextBox2.Text = newid
End With
TextBox3.ReadOnly = False
TextBox3.Focus()
Tag : .NET, Ms SQL Server 2008, Win (Windows App), VB.NET, VS 2008 (.NET 3.x), Windows
Sub autoid()
Dim tmpautoid As Integer = 0
Dim sqlauto As String
sqlauto = "SELECT Field From Table "
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_Depart_id.Text = Format("55-" + tmpautoid.ToString("000"))
End Sub