I am using a query to find keywords in a particular field, when i put the @parameter and then addparameter with value it does not work, however when i input the value directly, it works, anyone can help me pass value as parameter to my query please? below are my codes:
This works and retrieves any record with the word "My" in its title.
string cmdText = "SELECT * FROM tblshareknowledge where title LIKE '%My%'";
cmd = new MySqlCommand(cmdText, con);
//cmd.Parameters.AddWithValue("@myTitle", title);
This one does not work:
string cmdText = "SELECT * FROM tblshareknowledge where title LIKE '@myTitle'";
cmd = new MySqlCommand(cmdText, con);
cmd.Parameters.AddWithValue("@myTitle", title);
C programming language is a machine-independent programming language that is mainly used to create many types of applications and operating systems such as Windows, and other complicated programs such as the Oracle database, Git, Python interpreter, and games and is considered a programming foundation in the process of ...
C is an imperative procedural language supporting structured programming, lexical variable scope, and recursion, with a static type system. It was designed to be compiled to provide low-level access to memory and language constructs that map efficiently to machine instructions, all with minimal runtime support.
Compared to other languages—like Java, PHP, or C#—C is a relatively simple language to learn for anyone just starting to learn computer programming because of its limited number of keywords.
Full form of C is “COMPILE”. One thing which was missing in C language was further added to C++ that is 'the concept of CLASSES'.
You're currently putting your parameter within quotes, which means it's no longer being used as a parameter. I suspect you want:
string cmdText = "SELECT * FROM tblshareknowledge where title LIKE @myTitle";
cmd = new MySqlCommand(cmdText, con);
cmd.Parameters.AddWithValue("@myTitle", "%" + title + "%");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With