Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sql-server/21.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sql server textbox vb窗口窗体应用程序上的SQL Server结果_Sql Server_Visual Studio 2010_Textbox_Max - Fatal编程技术网

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
到我的ID
MAX()
函数是我的一种方法

我使用以下代码生成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