查询system.data.sqlite无法正常工作

时间:2015-10-30 17:44:49

标签: c# sqlite system.data.sqlite

我有一个带有名为File的表的sqlite数据库,它有一个名为FilePath的列,类型为Text。

在该表上有一个条目,其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");
}

我错过了什么吗?

1 个答案:

答案 0 :(得分:1)

'参数周围不需要单引号@where。你的代码应该是这样的:

SQLiteCommand cmd = 
new SQLiteCommand(@"SELECT FilePath FROM File WHERE FilePath = @Where", conn);
相关问题