【发布时间】:2013-02-07 09:03:39
【问题描述】:
我正在使用 Btngen 为我的 TextBox 生成一个 ID,我有 0001 并将其保存到我在 SQLSERVER 中的数据库中,问题是在我关闭程序并再次重新打开它之后,生成到我的值再次单击 Btngen 后的 TextBox 仍然是0001。我怎样才能避免这种情况?如何保留已经产生的价值并转移到下一个价值?我使用增量,但它仅在程序仍在运行时才有效,但如果我关闭程序并再次运行它会返回 0001 谁能告诉我该怎么做?
这是我的代码:
Dim p1num As Integer = 0
p1num += 1
txtPNumber.Text = p1num.ToString("D4")
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)
SQLcon.Open()
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
【问题讨论】: