我总是得到这个错误
near" s":语法错误
我的实施:
litecon.ConnectionString = "Data Source=" + AppAddress + "\\database\\mynew22.db;Version=3;UTF16Encoding=True";
从此方法中收到错误 - > 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
此选择命令之间没有区别......
"select * from mey where pe like '%" + str + "%'"
或
"select eng "
总是说" s":语法错误
答案 0 :(得分:2)
当str
的值包含撇号时,此查询将无效,因为该字符串将过早终止:
select * from mey where trans like '%King Solomon's Mines%'
你必须使用参数:
cmd = new SQLiteCommand("select * from mey where trans like @pattern", litecon);
cmd.Parameters.AddWithValue("@pattern", "%" + str + "%");
答案 1 :(得分:0)
答案 2 :(得分:0)
问题通常在于撇号。您可以使用它们,但必须加倍,如另一个答案所述,
select * from mey where trans like '%King Solomon's Mines%'
应该改为
select * from mey where trans like '%King Solomon''s Mines%'
。
快速解决方案是"select * from mey where trans like "+"'%King Solomon's Mines%'".Replace("'","''")
无论如何,这都会成功。