-
Query Problem
I'm trying to use Like, but don't know how to do it. This is my code:
searchAdapter = New OleDb.OleDbDataAdapter("Select * From ClientSystem WHERE Company_Name LIKE *@search*", connStr)
searchAdapter.SelectCommand.Parameters.AddWithValue("@search", txtSearch.Text)
May I ask also if this is possible, im creating a search button, need to check if the entered keyword is the Company_Name or Contact_Last_Name..
searchAdapter = New OleDb.OleDbDataAdapter("Select * From ClientSystem WHERE Company_Name OR Contact_Last_Name LIKE *@search*", connStr)
searchAdapter.SelectCommand.Parameters.AddWithValue("@search", txtSearch.Text)
Kindly help me to correct this problem.
-
Re: Query Problem
For the first part, add the wildcards (which may need to be % or *) to the parameter rather than the SQL statement, eg:
Code:
searchAdapter = New OleDb.OleDbDataAdapter("Select * From ClientSystem WHERE Company_Name LIKE @search", connStr)
searchAdapter.SelectCommand.Parameters.AddWithValue("@search", "*" & txtSearch.Text & "*")
For comparing a value to two fields, you need to write out the condition twice - and if apt (like in this case) also add extra parameters.