我已编写此代码以根据日期生成唯一 ID。问题是日期不是最新的。我想要这样的id
2013081901 - if user input data on 19/08/2013
2013082002 - if user input data on 20/08/2013
问题是,我有这样的身份证
2013081901 - user input data on 19/08/2013
2013081902 - user input data on 20/08/2013
这是我的代码:
Dim cnnOLEDB As New OleDbConnection(strConnectionString)
sql = "SELECT MAX(sampleID) FROM Spec_1"
cmd = New OleDbCommand(sql, cnnOLEDB)
cnnOLEDB.Open()
Dim dr As OleDbDataReader
dr = cmd.ExecuteReader()
While dr.Read()
Try
If Not IsDBNull(dr(0)) Then
txtSampleID.Text = (dr(0) + 1).ToString
'txtSampleID.Text = dr(0).ToString
Else
txtSampleID.Text = Format(Date.Today, "yyMMdd") + "01"
End If
Catch ex As Exception
txtSampleID.Text = "0"
End Try
End While