Imports System.Data.SqlClient
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
TextBox1.AutoCompleteMode = AutoCompleteMode.Suggest
TextBox1.AutoCompleteSource = AutoCompleteSource.CustomSource
Dim DataCollection As New AutoCompleteStringCollection()
getData(DataCollection)
TextBox1.AutoCompleteCustomSource = DataCollection
End Sub
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 = "Datasource=.\SQLEXPRESS.;Innitial Catalog=Pubs;ID=sa;password=123456"
Dim sql As String = "SELECT DISTINCT [NAME_EN] FrOM [train].[dbo].[EMP]"
connection = New SqlConnection(connetionString)
Try
connection.Open()
command = New SqlCommand(sql, connection)
adapter.SelectCommand = command
adapter.Fill(ds)
For Each row As DataRow In ds.Tables(0).Rows
dataCollection.Add(row(0).ToString())
Next
adapter.Dispose()
command.Dispose()
connection.Close()
Catch ex As Exception
MessageBox.Show("Can not open connection ! ")
End Try
End Sub
End Class
Tag : .NET, Win (Windows App), VB.NET, VS 2012 (.NET 4.x), Windows
connetionString = "Datasource=.\SQLEXPRESS.;Innitial Catalog=Pubs;ID=sa;password=123456"
Dim sql As String = "SELECT DISTINCT [NAME_EN] FrOM [train].[dbo].[EMP]"
connection = New SqlConnection(connetionString)
Try
connection.Open()
command = New SqlCommand(sql, connection)
adapter.SelectCommand = command
adapter.Fill(ds)
For Each row As DataRow In ds.Tables(0).Rows
dataCollection.Add(row(0).ToString())
Next
adapter.Dispose()
command.Dispose()
connection.Close()
Catch ex As Exception
MessageBox.Show("Can not open connection ! ")
End Try
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
'TODO: This line of code loads data into the 'TrainDataSet.EMP' table. You can move, or remove it, as needed.
Me.EMPTableAdapter.Fill(Me.TrainDataSet.EMP)
'TODO: This line of code loads data into the 'TrainDataSet._Train' table. You can move, or remove it, as needed.
Me._TrainTableAdapter.Fill(Me.TrainDataSet._Train)
Dim myNames = From n In TrainDataSet.EMP Select n.EN
TextBox1.AutoCompleteMode = AutoCompleteMode.Suggest
TextBox1.AutoCompleteSource = AutoCompleteSource.CustomSource
TextBox1.AutoCompleteCustomSource.AddRange(myNames.ToArray())
Label1.Text = myNames(5)
End Sub