473,748 Members | 10,737 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

What is the correct syntax to use MySQL LIKE query with parameters?

1 New Member
Hi All,

I am trying to query a mysql database using the 'LIKE' keyword within my query based on what the user has input.

It works if I pass the string, however I am having trouble getting it to expand the parameter when combining it with the LIKE MySQL keyword.

As seen below parameters work in a simple SELECT without 'LIKE':

Expand|Select|Wrap|Line Numbers
  1. string sql2 = "SELECT * FROM vocab WHERE english LIKE '%" + english + "%'";
  2. string sql3 = "SELECT * FROM vocab WHERE english LIKE '%" + "@English" + "%'";
  3. string sql4 = "SELECT * FROM vocab WHERE english =@English";
sql2 and sql4 both work and return data when entered through my application window. However sql3 doesn't as it doesn't seem to expand @English into whatever I have entered.

The single quotes around the % symbols are probably the cause but I can't figure it out.

Could someone please tell me the correct syntax for the statement in sql3?
Sep 3 '09 #1
0 2255

Sign in to post your reply or Sign up for a free account.

Similar topics

5
4011
by: red85 | last post by:
hello i have mysql 4.1 with win2000 SP3, i know that it is only an alpha and i don't know if someone else has already posted this problem: when i execute this sql UPDATE tableX SET fieldX=valueX WHERE id IN (SELECT tX.id FROM tableX AS tX WHERE tX.fieldY=valueY AND filedZ=valueZ);
0
1464
by: Arnold | last post by:
Hi, I'm using visual studio .NET 2003 enterprise and MySQL 5.0. I've created a database project in wich I like to create scripts for stored procedures and queries. I've created a connection using MyODBC 3.5.1 drivers and microsoft OLE DB provider for ODBC drivers as well as an OLE driver specificly for MySQL.
2
5318
by: ROBERT MELLOTT | last post by:
I am currently using VB 6.0 so I hope someone out there can help me. All I need is the proper syntax to reference the paramter in a SQL query. Here is my problem. I created a dataenvironment called: dataenvironment1. I then created a command called: command3 The command is a SQL query; INSERT INTO ControlTable VALUES (?,?). The SQL builder gives the parameters the names; param1 and param2.
8
9494
by: Nick | last post by:
I have a table with columns (product_id,related_product_id,related_counter) If product A is related to product B then a record should be created, if the record already exists then the related_counter should be incremented. This is very easy to do with MySQL using INSERT... ON DUPLICATE KEY. Standard or not, it is very usefull.
3
6735
by: brianbasquille | last post by:
Hello all, Strange little problem here... am just trying to insert some basic information into an Access Database using OleDB. I'm getting a "Syntax error in Insert Into statement" when it tries to execute the SQL. The strange thing is if i take the exact SQL being executed from the debugger and insert and execute it using the MS Access query engine, it works fine!
0
19281
by: IamtheEvster | last post by:
Hi All, I am currently using PHP 5 and MySQL 5, both on Fedora Core 5. I am unable to call a MySQL stored procedure that returns output parameters using mysql, mysqli, or PDO. I'm having a hell of a time with it... The following comes from phpinfo(): PHP Version: 5.1.2 mysql Client API version: 5.0.18 mysqli Client API version: 5.0.18
0
1168
by: boyindie86 | last post by:
Hi Forum, I am having some really iritating problems with an simple input page which should pass parameters into a stored procedure from the text boxes first and last name. I keep getting the error during exection of sp_myinsert, pfirstname not defined, every time i try to submit the form Has anyone got any suggestions I have giving my code for procedure and page many thanks boy
1
3370
by: ajos | last post by:
hi evrybdy, the problem is:- i had this running before in jsp but when i changed the jsp page using struts tags there occoured a problem... when i enter values in the 2 text boxes and click enter an exception occours which is- type Exception report message description The server encountered an internal error () that prevented it from fulfilling this request.
10
50021
by: bobf | last post by:
I am using a program 'My Contact Table' which is a code generator program. It allows you to easily create a PHP/MySQL web application without writing any code. I am trying to create an additional data entry page. I have copied an existing page and created a new table in my database. When I run the script I get the error message "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right...
0
8991
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8830
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
9321
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9247
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8242
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6074
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4602
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4874
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2782
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.