SQL Server结果在textbox vb窗口表单应用程序上

时间:2013-02-09 09:00:17

标签: sql-server visual-studio-2010 textbox max

SELECT的{​​{1}}声明和ListView的{​​{1}}声明,唯一的问题是我无法向ListBox显示结果我只是想用:

  

MAX()函数

我想使用DataGrid因为它会返回所选列的大值,因为我使用了TextBox来识别我的ID MAX()函数是我的一种方法它

我使用此代码生成ID:

INCREMENT

1 个答案:

答案 0 :(得分:1)

我试着理解你的问题,我认为你应该用这个:

尝试:

            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,则将其用于表单加载。

相关问题