问题描述
我想在我的更新 sql 中使用查询参数,并有以下代码:
I want to use query parameters in my update sql, and had this code:
internal static int UpdatePhotosetName(string oldPhotosetName, string newPhotosetName)
{
String qryUpdateBaseTable = "UPDATE PhotraxBaseData SET photosetName = @newName WHERE photosetName = @oldName";
int rowsUpdated;
using (var db = new SQLite.SQLiteConnection(App.DBPath))
{
SQLiteCommand cmd = new SQLiteCommand(db);
cmd.CommandText = qryUpdateBaseTable;
cmd.Parameters.Add(new SQLiteParameter("@newName"));
cmd.Parameters.Add(new SQLiteParameter("@oldName"));
Command.Parameters["@newName"].Value = newPhotosetName;
Command.Parameters["@oldName"].Value = oldPhotosetName;
rowsUpdated = cmd.ExecuteNonQuery();
db.Close();
}
return rowsUpdated;
}
...但以下所有内容在当前上下文中都被标记为不可用/不存在:
...but all of the following were flagged as being unavailable/nonexistent in the current context:
Parameters
SQLiteParameter
Command
我确实安装了 Sqlite-Net(SQLite.cs 和 SQLiteAsync.cs),以及SQLite for Windows Runtime (Windows 8.1)"的 3.8.7.1 版
I do have Sqlite-Net installed (SQLite.cs and SQLiteAsync.cs), and version 3.8.7.1 of "SQLite for Windows Runtime (Windows 8.1)"
我基于我在here中找到的代码,但显然是 WinRT 的做法这与更稳重的方式有很大不同.
I based this code on what I found here, but apparently the WinRT way of doing this differs significantly from the more staid way.
如何在 WinRT 应用中使用查询参数?
How can I utilize query parameters in a WinRT app?
我认为这不像一些花哨的 LINQ 那样性感,但它确实有效:
This is not as sexy as some fancy-pants LINQ, I reckon, but it does work:
internal static int UpdatePhotosetName(string oldPhotosetName, string newPhotosetName)
{
String qryUpdateBaseTable = String.Format(
@"UPDATE PhotraxBaseData SET photosetName = '{0}' WHERE photosetName = '{1}'",
newPhotosetName, oldPhotosetName);
int rowsUpdated;
using (var db = new SQLite.SQLiteConnection(App.DBPath))
{
SQLiteCommand cmd = new SQLiteCommand(db);
cmd.CommandText = qryUpdateBaseTable;
rowsUpdated = cmd.ExecuteNonQuery();
}
return rowsUpdated;
}
没关系;无论如何,我对我的编译器来说已经太性感了.
That's okay; I'm too sexy for my compiler already, anyway.
我想一个人永远不会太性感;毕竟,我要搭配 Thomas Levesque 的超修身造型:
I guess one can never really be too sexy; I'm going with Thomas Levesque's ultra-trim look, after all:
internal static int UpdatePhotosetName(string oldPhotosetName, string newPhotosetName)
{
String qryUpdateBaseTable = "UPDATE PhotraxBaseData SET photosetName = ? WHERE photosetName = ?";
int rowsUpdated;
using (var db = new SQLite.SQLiteConnection(App.DBPath))
{
rowsUpdated = db.Execute(qryUpdateBaseTable, newPhotosetName, oldPhotosetName); // look, ma: no superfluous code!
}
return rowsUpdated;
}
推荐答案
db.Execute("UPDATE PhotraxBaseData SET photosetName = ? WHERE photosetName = ?", newName, oldName);
这篇关于如何在 WinRT 应用程序中使用 SQLite 查询参数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!