Select query with Like function in MySQL

Last Reply one year ago By Mudassar

Posted one year ago

can someone help me with this code of mine. when i write things into the search box the search dosent work and here is the code

Dim adapater As MySqlDataAdapter
Dim ds As New DataSet
Try
con.Open()
adapater = New MySqlDataAdapter("SELECT * from inventory where Iterm like 'or" And TextBox1.Text & "%", con)
adapater.Fill(ds)
DataGridView1.DataSource = ds.Tables(0)
con.Close()


 

Posted one year ago

First of all 2 mistakes

1. You don't need to check for NULL with LIKE

2. You must use parameterized queries.

Dim cmd As MySqlCommand = New MySqlCommand("SELECT * from inventory where Iterm like @Iterm%")
cmd.Parameters.AddWithValue("@Iterm", TextBox1.Text)
cmd.Connection = con
Dim adapater As MySqlDataAdapter = New SqlDataAdapter(cmd)