[英]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.