VB.NET - How To Search Data In SQL And Show It On DataGridView Using Visual Basic.Net
In This VB.NET Tutorial We Will See How To Search Records From SqlServer Database On Button Click Event And Text Changed Event With Microsoft SQL DataBase Using Visual Basic .NET Programming Language.
Project Source Code:
Imports System.Data.SqlClient
Public Class VBNET_SQL_Datagridview_Search
Dim connection As New SqlConnection("Server= SAMSNG-PC; Database = TestDB; Integrated Security = true")
Private Sub VBNET_SQL_Datagridview_Search_Load(sender As Object, e As EventArgs) Handles MyBase.Load
FilterData("")
End Sub
Public Sub FilterData(valueToSearch As String)
'SELECT * From Users WHERE CONCAT(fname, lname, age) like '%F%'
Dim searchQuery As String = "SELECT * From Users WHERE CONCAT(fname, lname, age) like '%" & valueToSearch & "%'"
Dim command As New SqlCommand(searchQuery, connection)
Dim adapter As New SqlDataAdapter(command)
Dim table As New DataTable()
adapter.Fill(table)
DataGridView1.DataSource = table
End Sub
Private Sub BTN_FILTER_Click(sender As Object, e As EventArgs) Handles BTN_FILTER.Click
FilterData(TextBox1.Text)
End Sub
Private Sub TextBox1_TextChanged(sender As Object, e As EventArgs) Handles TextBox1.TextChanged
FilterData(TextBox1.Text)
End Sub
End Class
///////////////OUTPUT:
Download Projects Source Code
1 comments:
commentsHello, how can I add information to de DataGridView? Like "1", "Vb", "26", etc.
ReplyThanks for the tutorial, it helps me a lot.