!!!!!!! I found the solution!!! Below, I've included my investigation.
The solution is at the end.

I kind of see what you mean. Like if I put the parameter in the quoted
string, then the server will not treat it as a parameter. is that what
you mean?
but the following works:
       Dim str_search = New String("SELECT id, part_no, cust_part_no,
customer FROM table1 WHERE part_no = @input_part_no ")
       Dim sqlComm As New MySqlCommand(str_search,myConnection)
       sqlComm.Parameters.AddWithValue("@input_part_no",
search_part_no.Text)

It searches for the exact string that was inputed into the textbox
control called search_part_no. So I guess the server does see it as a
parameter, I think because of the '@' sign.

Oh, did I misunderstand you? You mean concatenate the percent signs?
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
If I do this:
       Dim str_search = New String("SELECT id, part_no, cust_part_no,
customer FROM table1 WHERE part_no LIKE '%' + @input_part_no + '%' ")

The ExecuteReader line gives an error.

       Exception Details: MySql.Data.MySqlClient.MySqlException: You
have an error in your SQL syntax; check the manual that corresponds to
your MySQL server version for the right syntax to use near '+ 'partno'
+ '%'' at line 1

       Source Error:
                             Dim dr As MySqlDataReader
                             myConnection.Open()
        Line 151:        dr = sqlComm.ExecuteReader

'where Line 151 is highlighted in red.

--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
If I do:
          "SELECT id, part_no, cust_part_no, customer FROM table1
WHERE part_no LIKE %" + @input_part_no + "% "

Then the error is:   Compiler Error Message: BC30037: Character is not
valid.
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
If I do:
           "SELECT id, part_no, cust_part_no, customer FROM table1
WHERE part_no LIKE '%''@input_part_no''%'"

There are no errors, but the search does not find any matches from the
database even when I know that the string I entered should find some
data.

--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
If I do:
           "SELECT id, part_no, cust_part_no, customer FROM table1
WHERE part_no LIKE concat('%','@input_part_no','%')"

Again no errors, but no search results either.

-------------------------------------------------**THE SOLUTION** for
MySQL, LIKE, similar matches, % %, parameterized statements, @ (hard
to google...)--------------------------------
If I do:
           "SELECT id, part_no, cust_part_no, customer FROM table1
WHERE part_no LIKE concat('%',@input_part_no,'%')"

It works! It returns the results based on similar expressions. ie,
results like "partno4" is returned even when the search string is
"rtno4", or like "rtno".
hurray! Thanks so much JoE!!! =D

Reply via email to