Hi guys!

I'm getting frustrated with my code because my filter in my query is not working.

All of the item_model in my receiving_details table were being suggested in auto complete but as you can see in my query that I'm filtering item model with a certain form_no.

Please help me.. Thank you.

    Private Sub item_suggest()

        Try

            SQLconn = New SqlConnection
            SQLconn.ConnectionString =
                "server=TOSOT_IT\TOSOT_SERVER;user=sa;password=cblls7890;database=TOSOT_DATABASE;"

            SQLconn.Open()

            Dim dt As New DataTable
            Dim ds As New DataSet
            ds.Tables.Add(dt)


            Dim da As New SqlDataAdapter(" SELECT item_model FROM receiving_details WHERE form_no= '" & txtFROM_NO.Text & "' ", SQLconn)
            da.Fill(dt)


            Dim r As DataRow

            txtITEM_MODEL.AutoCompleteCustomSource.Clear()

            For Each r In dt.Rows
                txtITEM_MODEL.AutoCompleteCustomSource.Add(r.Item(0).ToString)

            Next
            SQLconn.Close()


        Catch ex As Exception
            MessageBox.Show(ex.ToString)


        End Try
    End Sub

Here's a simple example how to create a custom autocomplete collection:

    ' Declare a collection
    public autoComp As AutoCompleteStringCollection

    ' Create a new collection instance
    autoComp = new AutoCompleteStringCollection()
    ' Or clear existing collection
    autoComp.Clear()

    ' Add your items to the collection
    autoComp.Add("first")
    autoComp.Add("fish")
    autoComp.Add("fast")

    ' Set these two properties for custom autocomplete to work
    textBox1.AutoCompleteMode = AutoCompleteMode.Suggest
    textBox1.AutoCompleteSource = AutoCompleteSource.CustomSource

    ' Finally, use your autocomplete collection
    textBox1.AutoCompleteCustomSource = autoComp

I hope you get the idea...

HTH

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.