关于 c#:SQLite 错误:在 \\”s\\” 附近:语法错误 | 珊瑚贝

SQLite Error: near “s”: syntax error


我总是得到这个错误

near”s”: syntax error

我的实现:

1
litecon.ConnectionString =“Data Source=” + AppAddress +\\\\database\\\\mynew22.db;Version=3;UTF16Encoding=True”;

从这个方法收到错误 -> liteda.Fill(dt);

1
2
3
4
5
6
7
        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

这个选择命令没有区别…

1
“select * from mey where pe like ‘%” + str +“%'”

1
“select eng”

总是说在 “s” 附近:语法错误

但如果使用 “xselect * from mey”,请在 “x” 附近说:语法错误

我正在使用这个库
http://adodotnetsqlite.sourceforge.net/

  • 你要求注射攻击…
  • 我的桌子是什么样子的?
  • @PinnyM no – str 是我的值/变量想要在我的数据库中找到它,它可以具有任何值,例如 ‘iran’、’usa’、….
  • 您是否尝试过用分号 (;) 终止查询?
  • @brianestey – 看到这个axgig.com/images/15579528865533473290.png
  • @PinnyM – 不起作用!
  • 好吧,您遇到了这样一个问题,即像这样处理命令而不是使用正确的参数化查询。以自己的方式进行操作,您会遇到不太”正确”的 SQL 语句,因为您没有平衡逗号或引号。使用参数化查询将让库为您完成工作并代表您处理它。获取它生成的 SQL 命令的副本(打印输出)。手动在您的数据库上运行它 – 您会得到什么?
  • 您可以跟踪正在使用的实际字符串(在添加 str 参数之后)并将其张贴在这里吗?
  • 我的查询在”SQLite Expert”中正常工作,但当我试图在我的程序中使用它时不起作用……
  • 我会再试一次问你:请打印出你的应用程序正在生成的 SQL,粘贴到这里。它与您手动运行的不同吗?帮助我们帮助您。 str 究竟是什么?
  • @PinnyM – 添加 str 后我的最终选择命令,我收到错误(str is ‘pengu’) -“select * from mey where pe like ‘%pengu%’;”
  • liteda 对象是否附加了任何其他查询?也许是 InsertCommand、UpdateCommand 或 DeleteCommand?你能发布与这个 liteda 对象的生命周期相关的代码吗?
  • @PinnyM – 我所有的实现 codepaste.net/z44hbe [访问正常] 但 SQLite 没有(所有命令)— 对不起我的英语不好
  • 您正在重用 liteda 对象,而没有从以前的查询中清除它。尝试为您正在运行的每个查询创建一个新的 SQLiteDataAdapter(工厂方法在这里很有用)。
  • @PinnyM – 只有这一部分有错误! codepaste.net/g1cshj


当 str 的值包含撇号时,此查询将不起作用,因为字符串将过早终止:

1
select * from mey where trans like ‘%King Solomon’s Mines%

你必须使用参数:

1
2
cmd = new SQLiteCommand(“select * from mey where trans like @pattern”, litecon);
cmd.Parameters.AddWithValue(“@pattern”,“%” + str +“%”);
  • 不起作用 – 我尝试使用这个命令,”select * from mey where trans like ‘%tr%'” – 但收到(靠近”s”:语法错误)
  • 所以是 select 失败了;你可能在那里有一些控制字符。


问题通常与撇号有关。您可以使用它们,但必须像另一个答案中提到的那样加倍,

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(“‘”,”””)

无论如何都会成功的。


问题解决了!

使用了这些库,问题就解决了……
http://www.devart.com/dotconnect/sqlite/download.html


谢谢大家


来源:https://www.codenong.com/17280051/

微信公众号
手机浏览(小程序)

Warning: get_headers(): SSL operation failed with code 1. OpenSSL Error messages: error:14090086:SSL routines:ssl3_get_server_certificate:certificate verify failed in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57

Warning: get_headers(): Failed to enable crypto in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57

Warning: get_headers(https://static.shanhubei.com/qrcode/qrcode_viewid_9998.jpg): failed to open stream: operation failed in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57
0
分享到:
没有账号? 忘记密码?