How to send a parameter in a LIKE query

0

My problem is that I'm doing a form, and I have a txt that is responsible for searching, but I have to put the manual data in the query to work, and what I want is to take the value of txt to search from here: I leave the code in summary View

<td>
 <asp:TextBox CssClass="form-control" ID="txt_clasif" runat="server"   ReadOnly="false"   Text=""></asp:TextBox>
</td>

Query:

Dim buscarclasif As String = txt_clasif.Text

sqlQuery = sqlQuery & " and tc.nombre_clasif  like '%%'"

Inside the percents I put my values but I do not know how to put what goes in my search text box:

dbComm = New MySqlCommand(sqlQuery, dbConn)
dbComm.Parameters.AddWithValue("?nombre_clasif", buscarclasif)
    
asked by Jonathan 10.12.2018 в 20:51
source

1 answer

-1

Your query is a string that does not receive parameters as such, the parameters you use when you use a stored procedure, in this case you must concatenate the value of the textbox with your query.

sqlQuery = sqlQuery & " and tc.nombre_clasif  like '%" & buscarclasif & "%'"

In addition to this example implementation ... you should worry about this and all your querys that you do to prevent the sql injection (chains that can modify your main query and execute code that does not correspond to the behavior that the application must have).

    
answered by 10.12.2018 в 21:32