Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQLite prepared Statement not working on SQLiteDateReader?

Here is my code

SQLiteConnection connection = new SQLiteConnection("Data Source=userData.dat;version=3;");
connection.Open();

SQLiteCommand cmd = connection.CreateCommand();

cmd.CommandText = "SELECT * FROM tags WHERE tags_tags LIKE '%@tags_tags%' ORDER by tags_id DESC LIMIT 0, 100";
cmd.Parameters.Add("@tags_tags", DbType.String);
cmd.Parameters["@tags_tags"].Value = tags;


SQLiteDataReader reader = cmd.ExecuteReader();
var _sql = cmd.CommandText;
MessageBox.Show(_sql);//still shows "SELECT * FROM tags WHERE tags_tags LIKE '%@tags_tags%' ORDER by tags_id DESC LIMIT 0, 100"

I also used cmd.Parameters.AddWithValue but not worked...
Where is the mistake?

like image 414
Soroush Khosravi Avatar asked Dec 06 '25 02:12

Soroush Khosravi


1 Answers

concatenate the parameter in your string, eg

LIKE '%' || @tags_tags || '%'

you are enclosing the parameter with single quotes, thus making it a value. remove the single quotes and concatenate the percent symbol on the value of the parameter.

LIKE @tags_tags

and in your parameters,

cmd.Parameters["@tags_tags"].Value = '%' + tags + '%';
like image 98
John Woo Avatar answered Dec 07 '25 17:12

John Woo