hey guys i need some help on my Search button

It seems that it is not accepting the data on the cboSI.text which contains the Field Names of the Table

Heres the Code:

Private Sub cmdSearch_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdSearch.Click
        Try
            Dim d3 As New MySqlDataAdapter("select * from tblbooks where '" & cboSI.Text = "ISBN" Or "Title" Or "Author" Or "Publisher" Or "Category" & "'  like '" & txtSF.Text & "'", connstr)
            Dim d4 As New DataTable
            d3.Fill(d4)
            dgvBooks.DataSource = d4
        Catch ex As Exception
            MsgBox(Err.Description)
        End Try
    End Sub

But if i tried to Directly put the field name

Dim d3 As New MySqlDataAdapter("select * from tblbooks where ISBN like '" & txtSF.Text & "'", connstr)

It works but only for ISBN cause its the only field name that i put there

aslo i wanted to change it output to Highlighting the Data in the DataGridVie instead of just showing the specific search cause that is for Sorting the Field Name's Data

Try it this way:

Private Sub cmdSearch_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdSearch.Click
       IF cboSI.Text = "ISBN" Or cboSI.Text = "Title" Or cboSI.Text = "Author" Or cboSI.Text = "Publisher" Or cboSI.Text = "Category" Then
       Try
            Dim d3 As New MySqlDataAdapter("select * from tblbooks where " & cboSI.Text "  like '%" & txtSF.Text & "%'", connstr)
            Dim d4 As New DataTable
            d3.Fill(d4)
            dgvBooks.DataSource = d4
        Catch ex As Exception
            MsgBox(Err.Description)
        End Try
    else 
    msgbox("Wrong search parameters")
    End Sub

PS1: I haven't tested this, so it might contain typos
PS2: I've used MS SQL wildcards, you might want to check out if you need them

It Worked Thank you

Please mark this as solved, thanks.

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.