Berikut adalah cara membuat pencarian data dengan Textbox pada DataGrid
lalu tambahkan sintax seperti dibawah ini :
Imports MySql.Data.MySqlClient
Public Class Form1
Dim svr As String = "localhost"
Dim uid As String = "root"
Dim pwd As String = ""
Dim db As String = "dtbase"
Dim cConn As New MySqlConnection
'Membuat Koneksi
Sub Koneksi()
cConn.ConnectionString = "server= " + svr + "; user id=" + uid + "; password=" + pwd + "; database=" + db + ""
Try
cConn.Open()
Finally
cConn.Dispose()
End Try
End Sub
Private Sub Form_Load()
Call Koneksi()
' Memanggil table karyawan
da = New MySqlDataAdapter("Select * from karyawan", conn):
ds = New DataSet
da.Fill(ds, "karyawan")
DataGridView1.DataSource = ds.Tables("karyawan")
End Sub
Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged
Dim xloop1 As Integer
Dim sPola As String
Dim sbuka As String
Dim SBetul As Boolean
sPola = TextBox1.Text + "*"
With DataGridView1
For xloop1 = 1 To .RowCount - 1
sbuka = .Rows(xloop1 - 1).Cells(0).Value
SBetul = UCase(sbuka) Like UCase(sPola)
If SBetul = True Then
.CurrentCell = .Item(0, xloop1 - 1)
Exit Sub
End If
Next
End With
End Sub
End Class
Jalankan tekan F5, lalu ditampilkan layout seperti dibawah ini :