如何从自动填充文本框中检索数据

时间:2018-12-31 09:29:57

标签: sql vb.net

我正在使用库存管理系统,并且添加了具有自动完成代码的文本框。.我有两种形式,一种是项目表单,另一种是库存中。现在,我可以从具有自动完成代码的stockin itemnumber文本框中获取itemcodeID。我选择的项目编号没有给出我的描述。.我的意思是说,如果用户搜索库存形式的项目代码,那么他应该自动获得该项目的描述和数量...我正在使用vb.net和ms sql。

我的自动完成代码

Private Sub getData(ByVal dataCollection As AutoCompleteStringCollection)
    Dim connetionString As String = Nothing
    Dim connection As SqlConnection
    Dim command As SqlCommand
    Dim adapter As New SqlDataAdapter()
    Dim ds As New DataSet()

    connetionString = ("Server= DESKTOP-QN6F623; Database = dbo_main;Integrated Security = false;User ID=dis;Password=0m3rP@ss")
    Dim sql As String = "SELECT itemnumber FROM items"
    connection = New SqlConnection(connetionString)
    Try
        connection.Open()
        command = New SqlCommand(sql, connection)
        adapter.SelectCommand = command
        adapter.Fill(ds)
        adapter.Dispose()
        command.Dispose()
        connection.Close()
        For Each row As DataRow In ds.Tables(0).Rows
            dataCollection.Add(row(0).ToString())
        Next
    Catch ex As Exception
        MessageBox.Show("Can not open connection ! ")
    End Try
End Sub

Private Sub stockin_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    Stockin_itemnumberTextBox.AutoCompleteMode = AutoCompleteMode.Suggest
    Stockin_itemnumberTextBox.AutoCompleteSource = AutoCompleteSource.CustomSource
    Dim DataCollection As New AutoCompleteStringCollection()
    getData(DataCollection)
    Stockin_itemnumberTextBox.AutoCompleteCustomSource = DataCollection
End Sub

我需要...。当用户在itemnumber文本框中输入内容时,他应该获取与该编号自动相关的相关详细信息... textbox的itemnumber是自动完成的。

0 个答案:

没有答案