我試圖理解你的問題,我認爲你應該使用這樣的:
嘗試:
Dim querystring As String = "SELECT MAX(pIDNo) FROM (Name of your Table)"
Using connection As New SqlConnection("Data Source=(local);Initial Catalog=(Name of your DB);Persist Security Info=True;User ID=(Your User);Password=(Your Pass)")
Dim command As New SqlCommand(querystring, connection)
connection.Open()
Dim reader As SqlDataReader = command.ExecuteReader
Dim value = String.Empty
While reader.Read
value = reader.GetString(0)
End While
txtPNumber.Text = Today.Year.ToString().Substring(2, 2) & Today.Month.ToString().PadLeft(2, "0") & (Integer.Parse(value.Substring(4, value.Length - 4)) + 1).ToString("D4")
End Using
Catch ex As Exception
txtPNumber.Text = Today.Year.ToString().Substring(2, 2) & Today.Month.ToString().PadLeft(2, "0") & num.ToString("D4")
End Try
儘量使一個Private Sub與它一起使用,如果你想在程序運行之後顯示它,或者如果你想要一個觸發器來顯示你想要的ID,你可以在按鈕上使用它。
你的代碼在哪裏?........你的問題在哪裏? – andy 2013-02-09 11:48:05