please give me full coding for searching data from textbox and display it in gridview.

Hi,

This code is not the best but it works..

Private Sub btnSearch_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSearch.Click
If txtSearch.Text.Trim.Length = 0 Then
MsgBox("Search Box cannot be empty! Please put something to search.", MsgBoxStyle.Critical)
End If
Dim mMySQLConnectionString As String = My.Settings.MySQLConnectionString
Dim MyADOConnection As New MySqlConnection
MyADOConnection.ConnectionString = mMySQLConnectionString
Dim mMySqlCommand As New MySqlCommand
Dim mMySqlAdapter As New MySqlDataAdapter
Dim mMyData As New DataTable
dgvSuppliers.DataSource = Nothing
Try
MyADOConnection.Open()
mMySqlCommand.Connection = MyADOConnection
mMySqlCommand.CommandText = "SELECT Code, Name, Phone, Fax, Email, Website FROM Suppliers WHERE Code LIKE '" & txtSearch.Text & "' OR Name LIKE '" & txtSearch.Text & "%" & "' OR fax LIKE '" & txtSearch.Text & "%" & "'"
mMySqlAdapter.SelectCommand = mMySqlCommand
mMySqlAdapter.Fill(mMyData)
dgvSuppliers.DataSource = mMyData
dgvSuppliers.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.DisplayedCells

mMySQLConnectionString = Nothing
MyADOConnection = Nothing
mMySqlCommand = Nothing
mMySqlAdapter = Nothing
mMyData = Nothing

Catch ex As Exception
MsgBox(ex.Message)

End Try
End Sub

please give me full coding for searching data from textbox and display it in gridview using vb.net and Access.

This should suffice. Just how to display the result in datagridview, do some research. It's not that difficult.

Conn = New OleDbConnection("provider=Microsoft.Jet.OLEDB.4.0; Data Source =KDE.mdb;")
            Conn.Open()
            If comBoxSearch.Text = "Member ID" Then
                Str = "SELECT * FROM members WHERE memberid = '" & txtInput.Text & "'"
            Else
                Str = "SELECT * FROM members WHERE NRIC = '" & txtInput.Text & "'"
            End If
            Cmd = New OleDbCommand(Str, Conn)
            Dir = Cmd.ExecuteReader
            Dir.Read()
            If Dir.HasRows Then
                MemSrcResult.lblID.Text = Dir(0)
                MemSrcResult.txtFirstName.Text = Dir(1)
                MemSrcResult.txtMiddleName.Text = Dir(2)
                MemSrcResult.txtLastName.Text = Dir(3)
                MemSrcResult.txtTitle.Text = Dir(4)
                MemSrcResult.txtNRIC.Text = Dir(5)
                MemSrcResult.txtDateOfBirth.Text = Dir(6)
                MemSrcResult.txtCompany.Text = Dir(7)
                MemSrcResult.txtProfession.Text = Dir(8)
                MemSrcResult.txtOfficeNo.Text = Dir(9)
                MemSrcResult.txtOfficeAdd.Text = Dir(10)
                MemSrcResult.txtContact.Text = Dir(11)
                MemSrcResult.txtHouseAdd.Text = Dir(12)
                MemSrcResult.lblJoinedDate.Text = Dir(13)
                MemSrcResult.lblStatus.Text = Dir(14)
                If Dir(14) = "ACTIVE" Then
                    MemSrcResult.lblStatus.ForeColor = Color.Green
                Else
                    MemSrcResult.lblStatus.ForeColor = Color.Red
                End If
                MemSrcResult.Show()
                Dir.Close()
                Conn.Close()
            Else
                MsgBox("No such record found.", MsgBoxStyle.Exclamation)
            End If

i want to ask ..

My.Settings.MySQLConnectionString

this is refer to?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.