Search code examples
c#sqlitewindows-8windows-runtime

How can I use SQLite query parameters in a WinRT app?


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

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)"

I based this code on what I found here, but apparently the WinRT way of doing this differs significantly from the more staid way.

How can I utilize query parameters in a WinRT app?


Solution

  • db.Execute("UPDATE PhotraxBaseData SET photosetName = ? WHERE photosetName = ?", newName, oldName);