Reputation: 71
me always get this error
near "s": syntax error
my implementation:
litecon.ConnectionString = "Data Source=" + AppAddress + "\\database\\mynew22.db;Version=3;UTF16Encoding=True";
error recived form this method -> liteda.Fill(dt);
if (lang == "FaToMe")
liteda.SelectCommand = new SQLiteCommand("select * from mey where trans like '%" + str + "%'", litecon);
else
liteda.SelectCommand = new SQLiteCommand("select * from mey where pe like '%" + str + "%'", litecon);
DataTable dt = new DataTable();
liteda.Fill(dt); //liteda is SQLiteDataAdapter
no difference between this select commands...
"select * from mey where pe like '%" + str + "%'"
or
"select eng "
always say near "s": syntax error
i'm using this library http://adodotnetsqlite.sourceforge.net/
Upvotes: 5
Views: 12918
Reputation: 1077
The problem is usually with apostrophe. You CAN use them but has to be doubled like, as mentioned in another answer,
select * from mey where trans like '%King Solomon's Mines%'
should changed to
select * from mey where trans like '%King Solomon''s Mines%'
.
A quick solution is to do "select * from mey where trans like "+"'%King Solomon's Mines%'".Replace("'","''")
That would succeed in any case.
Upvotes: 4
Reputation: 71
The problem was solved!
used these library and The problem was solved... http://www.devart.com/dotconnect/sqlite/download.html
thanks guys
Upvotes: 0
Reputation: 180020
When str
has a value containing an apostrophe, this query will not work because the string will be terminated too early:
select * from mey where trans like '%King Solomon's Mines%'
You must use parameters:
cmd = new SQLiteCommand("select * from mey where trans like @pattern", litecon);
cmd.Parameters.AddWithValue("@pattern", "%" + str + "%");
Upvotes: 6