gpt4 book ai didi

c# - 对 system.data.sqlite 的查询不起作用

转载 作者:行者123 更新时间:2023-12-02 02:17:57 24 4
gpt4 key购买 nike

我有一个 sqlite 数据库,其中包含名为 File 的表,其中有一列名为 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");
}

我错过了什么吗?

最佳答案

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

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

关于c# - 对 system.data.sqlite 的查询不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33441948/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com