Sql server textbox vb窗口窗体应用程序上的SQL Server结果
对于Sql server textbox vb窗口窗体应用程序上的SQL Server结果,sql-server,visual-studio-2010,textbox,max,Sql Server,Visual Studio 2010,Textbox,Max,对于ListView和ListBox甚至对于DataGrid我都有一个SELECT语句。唯一的问题是我无法将结果显示到我的TextBox我只想使用: MAX()函数 我想使用MAX(),因为它说它将返回所选列的最大值,因为我使用INCREMENT到我的IDMAX()函数是我的一种方法 我使用以下代码生成ID: Dim p1num As Integer = 0 p1num += 1 txtPNumber.Text = p1num.ToString("D4") 我试着理解你的问题
ListView
和ListBox
甚至对于DataGrid
我都有一个SELECT
语句。唯一的问题是我无法将结果显示到我的TextBox
我只想使用:
MAX()函数
我想使用MAX()
,因为它说它将返回所选列的最大值,因为我使用INCREMENT
到我的IDMAX()
函数是我的一种方法
我使用以下代码生成ID:
Dim p1num As Integer = 0
p1num += 1
txtPNumber.Text = p1num.ToString("D4")
我试着理解你的问题,我认为你应该用这个: 尝试:
如果您想在程序运行后显示它,请尝试使用它制作一个专用Sub,并将其用于表单加载;如果您想使用触发器显示您想要的ID,请使用on按钮。代码在哪里?。。。。。。。。你的问题出在哪里?
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