我在Windows Phone 8.1应用程序上使用SqlitePCL, 我有查询选择和插入工作但由于某种原因删除和更新不起作用
以下是我的代码:
选择声明:
public static itemPassword[] AllGetItemPassword()
{
var db = App.conn;
int numbofPass = 0;
itemPassword[] itmpass = null;
try
{
using (var statement = db.Prepare("SELECT nameWeb, username, password, link FROM Passwords"))
{
while (statement.Step() == SQLiteResult.ROW)
{
numbofPass++;
}
}
}
catch
{
}
插入声明:
public void insertToDB(String usernameWeb, String userusername, String userpassword, String userlink)
{
var db = App.conn;
try
{
using (var pass = db.Prepare("INSERT INTO Passwords (nameWeb, username, password, link) VALUES (?,?,?,?)"))
{
pass.Bind(1, usernameWeb);
pass.Bind(2, "Username: " + userusername);
pass.Bind(3, "Password: " + userpassword);
pass.Bind(4, "Link: " + userlink);
pass.Step();
}
}
catch
{
}
现在不行的代码:
删除声明:
public static void DeleteRecord12(string webname, string username , string password, string link)
{
var db = App.conn;
try
{
using (var pass = db.Prepare("DELETE FROM Passwords WHERE webname = ? AND username = ? AND password = ? AND link = ?"))
{
pass.Bind(1, webname);
pass.Bind(2, username);
pass.Bind(3, password);
pass.Bind(4, link);
pass.Step();
}
}
catch (Exception ex)
{
ex.GetType();
}
}
更新声明:
public void UpdateRecord(string webname, string username, string password, string link,string Newwebname, string Newusername, string Newpassword, string Newlink)
{
var db = App.conn;
try
{
using (var pass = db.Prepare("UPDATE Passwords SET webname = ?, username = ?, password = ?, link = ? WHERE webname = ? AND username = ? AND password = ? AND link = ?"))
{
pass.Bind(1, Newwebname);
pass.Bind(2, Newusername);
pass.Bind(3, Newpassword);
pass.Bind(4, Newlink);
pass.Bind(5, webname);
pass.Bind(6, username);
pass.Bind(7, password);
pass.Bind(8, link);
pass.Step();
}
}
catch (Exception ex)
{
ex.GetType();
}
}
更新 似乎windows手机上的sqlite Pcl并不支持命令"更新"当选择或删除WHERE命令时,仅支持" WHERE id =?"而不是像#34; WHERE name = belal"。
答案 0 :(得分:0)
您将文字文本放在用户名和insert语句中的其他变量之前。因此,在更新或删除记录时从未找到记录。删除insert语句的绑定中变量前面的标签以使其起作用:
public void insertToDB(String usernameWeb, String userusername, String userpassword, String userlink)
{
var db = App.conn;
try
{
using (var pass = db.Prepare("INSERT INTO Passwords (nameWeb, username, password, link) VALUES (?,?,?,?)"))
{
pass.Bind(1, usernameWeb);
pass.Bind(2, userusername);
pass.Bind(3, userpassword);
pass.Bind(4, userlink);
pass.Step();
}
}
catch
{
}