0

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

2
Contributors
3
Replies
4
Views
4 Years
Discussion Span
Last Post by adam_k
0

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

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.