【问题标题】:query on system.data.sqlite not working对 system.data.sqlite 的查询不起作用
【发布时间】:2015-10-30 17:44:49
【问题描述】:

我有一个带有名为 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");
}

我错过了什么吗?

【问题讨论】:

    标签: c# sqlite system.data.sqlite


    【解决方案1】:

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-05-04
      • 2014-09-06
      • 1970-01-01
      • 2019-07-24
      • 2020-06-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多