Private Sub username_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles username.TextChanged
Dim dt As New DataTable
Dim str As String
Dim index As Integer = 0
str = "SELECT UserEsynergy,PwdESynergy FROM Employee "
strKeyWord = Me.username.Text
' strKeyWordP = Me.password.Text
PopulateData()
End Sub
Private Sub PopulateData()
Dim objConn As SqlConnection
Dim dtAdapter As SqlDataAdapter
Dim dt As New DataTable
Dim da As New SqlDataAdapter
Dim strConnString As String
strConnString = "Data Source=PONGWICS2014-PC; Initial Catalog=Top_CustomerEntry;User ID=sa;Password=Pong"
objConn = New SqlConnection(strConnString)
Dim myCommand As SqlCommand = New SqlCommand(str, connetionString)
objConn.Open()
Dim strSQL As String
strSQL = "SELECT * FROM Employee WHERE 1=1 "
If strKeyWord <> "" Then
strSQL = strSQL & " AND UserEsynergy Like '%" & strKeyWord & "%' "
End If
dtAdapter = New SqlDataAdapter(strSQL, objConn)
dtAdapter.Fill(dt)
dtAdapter = Nothing
objConn.Close()
objConn = Nothing
Me.DataGridView1.DataSource = dt
Me.DataGridView1.Columns.Clear()
With (DataGridView1.ColumnHeadersDefaultCellStyle)
.BackColor = Color.Navy
.ForeColor = Color.White
.Font = New Font(songsDataGridView.Font, FontStyle.Bold)
End With
Dim ColumnTextBox As DataGridViewTextBoxColumn
Dim ColumnCheckBox As New DataGridViewCheckBoxColumn()
ColumnCheckBox.Width = 30
ColumnCheckBox.DataPropertyName = "Select from UserEsynergy = '" & username.Text & "'"
Me.DataGridView1.Columns.Add(ColumnCheckBox)
Dim ckBox As New CheckBox()
Dim rect As Rectangle = DataGridView1.GetCellDisplayRectangle(0, -1, True)
ckBox.Size = New Size(18, 18)
rect.X = rect.Location.X + (rect.Width / 4)
ckBox.Location = rect.Location
' AddHandler (ckBox.CheckedChanged), New EventHandler(AddressOf ckBox_CheckedChanged)
Me.DataGridView1.Controls.Add(ckBox)
Dim com As New SqlCommand()
DataGridView1.Columns(0).Frozen = False
ColumnTextBox = New DataGridViewTextBoxColumn()
ColumnTextBox.DataPropertyName = "ID"
ColumnTextBox.HeaderText = "ID"
ColumnTextBox.HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter
' ColumnTextBox.Width = 100
Me.DataGridView1.Columns.Add(ColumnTextBox)
ColumnTextBox = New DataGridViewTextBoxColumn()
ColumnTextBox.DataPropertyName = "UserEsynergy"
ColumnTextBox.HeaderText = "UserEsynergy"
ColumnTextBox.HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter
' ColumnTextBox.Width = 100
Me.DataGridView1.Columns.Add(ColumnTextBox)
ColumnTextBox = New DataGridViewTextBoxColumn()
ColumnTextBox.DataPropertyName = "PwdESynergy"
ColumnTextBox.HeaderText = "PwdESynergy"
ColumnTextBox.HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter
' ColumnTextBox.Width = 100
Me.DataGridView1.Columns.Add(ColumnTextBox)
ColumnTextBox = New DataGridViewTextBoxColumn()
ColumnTextBox.DataPropertyName = "IDEmp"
ColumnTextBox.HeaderText = "IDEmp"
ColumnTextBox.HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter
' ColumnTextBox.Width = 100
Me.DataGridView1.Columns.Add(ColumnTextBox)
ColumnTextBox = New DataGridViewTextBoxColumn()
ColumnTextBox.DataPropertyName = "Ename"
ColumnTextBox.HeaderText = "Ename"
ColumnTextBox.HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter
' ColumnTextBox.Width = 100
Me.DataGridView1.Columns.Add(ColumnTextBox)
ColumnTextBox = New DataGridViewTextBoxColumn()
ColumnTextBox.DataPropertyName = "Tname"
ColumnTextBox.HeaderText = "Tname"
ColumnTextBox.HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter
' ColumnTextBox.Width = 100
Me.DataGridView1.Columns.Add(ColumnTextBox)
ColumnTextBox = New DataGridViewTextBoxColumn()
ColumnTextBox.DataPropertyName = "TNickName"
ColumnTextBox.HeaderText = "TNickName"
ColumnTextBox.HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter
' ColumnTextBox.Width = 100
Me.DataGridView1.Columns.Add(ColumnTextBox)
ColumnTextBox = New DataGridViewTextBoxColumn()
ColumnTextBox.DataPropertyName = "Position"
ColumnTextBox.HeaderText = "Position"""
ColumnTextBox.HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter
' ColumnTextBox.Width = 100
Me.DataGridView1.Columns.Add(ColumnTextBox)
End Sub
Tag : .NET, Ms SQL Server 2008, Ms SQL Server 2012, VB.NET, VS 2008 (.NET 3.x), VS 2010 (.NET 4.x)