プログラムに問題がINCREMENT
あり、特定の値が必要ですLabel
Dim p1num As Integer = 0
M.Text = Format(Now, "MM")
Y.Text = Format(Now, "yy")
txtPNumber.Text = Y.Text.ToString & M.Text.ToString & p1num.ToString("D4")
これを使用して患者 ID を生成します。ここで、M は月、Y は年 + p1num を使用して 4 桁の数字を作成します。出力は次のようになります。
(現在の日付と年を使用しましょう)
13020001
13020002
13020003
13020004
等々....
この後、これらのコードを使用して SQL SERVER の DB に挿入します。
Dim SQLcon As New SqlConnection
Dim SQLdr As SqlDataReader
Try
SQLcon.ConnectionString = "Data Source=####;" & _
"Initial Catalog=####;Persist Security Info=True;User ID=####;Password="
Dim SQLcmd As New SqlCommand("INSERT INTO dbo.Patients" & _
"(pIDNo)" & _
"VALUES(@pIDNo)", SQLcon)
SQLcmd.Parameters.AddWithValue("@pIDNo", txtPNumber.Text)
MsgBox("Patient Added!", MsgBoxStyle.Information)
SQLdr = SQLcmd.ExecuteReader()
Catch ex As Exception
MessageBox.Show("Error Occured, Can't Add Patient!" & ex.Message)
Finally
SQLcon.Close()
End Try
Return ""
問題は、プログラムを閉じると、生成される値がTextBox
常に 13020001 で始まることです。最近追加した値を保持し、それを +1 に増やしたいので、追加したばかりの現在の ID を表示する予定です。これらを使用して私のDB:
Dim querystring As String = "SELECT MAX(pIDNo) FROM dbo.Patients"
Using connection As New SqlConnection("Data Source=####;" & _
"Initial Catalog=####;Persist Security Info=True;User ID=####;Password=")
Dim command As New SqlCommand(querystring, connection)
connection.Open()
Dim reader As SqlDataReader = command.ExecuteReader
While reader.Read
txtCurrentID.Text = reader.GetString(0)
End While
reader.Close()
現在の ID を表示することはできましたが、問題は 1 ずつインクリメントできないことです。
その他の問題 : 表示された値をコピーして 1 ずつ追加しようとしましたが、別の問題が発生しました。月と年は変わりません。月「MARCH」に達した場合、生成される値はまだです
1302 + pnum1.text("D4") 1303 + pnum1.text("D4") であるはず
1302 は 2 月用 1303 は 3 月用
誰でも私の問題を解決できますか?