[英]query on system.data.sqlite not working
我有一个带表名为File的sqlite数据库,该表有一个名为FilePath的文本类型的列。
在该表上有一个条目,其FilePath的值为f9a35e24-bce9-46c8-bbc0-02a005455fe3
(随机GUID的toString)。
如果我在SQLiteStudio上尝试以下查询,它将输出条目。
SELECT FilePath FROM File WHERE FilePath = 'f9a35e24-bce9-46c8-bbc0-02a005455fe3'
但是,使用下面的代码使用System.Data.SQLite
外部程序集,它将永远不会检索该条目。
SQLiteConnection conn = new SQLiteConnection(connectionString);
SQLiteCommand cmd =
new SQLiteCommand(@"SELECT FilePath FROM File WHERE FilePath = '@Where';", conn);
cmd.Parameters.Add("@Where", DbType.String).Value =
"f9a35e24-bce9-46c8-bbc0-02a005455fe3";
conn.Open();
SQLiteDataReader dr = cmd.ExecuteReader();
if (dr.Read())
{
Console.WriteLine("yes");
}
else
{
Console.WriteLine("not");
}
我想念什么吗?
您不需要在@where
参数周围使用单引号'
。 您的代码应如下所示:
SQLiteCommand cmd =
new SQLiteCommand(@"SELECT FilePath FROM File WHERE FilePath = @Where", conn);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.