gkan 12
gkan 12

Reputation: 39

How I Do Text Box Instant Search From SQL Server Table Column Vb.NET

I have use the below coding but it show the error i want the sql server table column show in textbox instant search ...

Private Sub TextBox_4_TextChanged(sender As System.Object, e As System.EventArgs) Handles TextBox_4.TextChanged
        Dim Connection As New SqlConnection(connectionString)
        Dim command As New SqlCommand("select * from Table_Entry Order By Item_Urdu", Connection)
        Dim adapter1 As New SqlDataAdapter(command)
        Dim table1 As New DataTable()
        adapter1.Fill(table1)
        Dim row As DataRow = table1.NewRow()
        row(0) = 0
        row(1) = ""
        table1.Rows.InsertAt(row, 0)
        TextBox_4.AutoCompleteCustomSource = table1
    End Sub

Upvotes: 1

Views: 176

Answers (1)

gkan 12
gkan 12

Reputation: 39

Imports System.Drawing.Printing
Imports System
Imports System.Collections.Generic
Imports System.ComponentModel
Imports System.Data
Imports System.Drawing
Imports System.Linq
Imports System.Text
Imports System.Threading.Tasks
Imports System.Windows.Forms
Imports System.Drawing.Design
Imports System.Drawing.Text
Imports System.Data.SqlClient
Imports System.Data.Sql
Imports System.IO
Imports System.Configuration
Public Class Form1
    Dim connectionString As String = "Data Source=PC1-PC;Initial Catalog=Test2;Integrated Security=True"
    Dim cn As New SqlConnection(connectionString)
    Dim dr As SqlDataAdapter
    Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
        Dim cmd As New SqlCommand("SELECT Item_Urdu FROM table_33", cn)
        Dim ds As New DataTable
        Dim da As New SqlDataAdapter(cmd)
        Dim col As New AutoCompleteStringCollection
        da.Fill(ds)
        For i = 0 To ds.Rows.Count - 1
            col.Add(ds.Rows(i)("Item_Urdu").ToString())
        Next
        TextBox1.AutoCompleteSource = AutoCompleteSource.CustomSource
        TextBox1.AutoCompleteCustomSource = col
        TextBox1.AutoCompleteMode = AutoCompleteMode.Suggest
    End Sub
End Class

Upvotes: 1

Related Questions