I can't put the 'db.update' statement to work. When I try to read the database, it always reads the very first data inserted from the else statement. I have traced my program and it does reach the db.update and the values being passed is correct but when I read the table the values don't change.
I'm making a windows store app in windows 8.1 using Visual Studio 2013
here's my code
LastRead dataref = new LastRead { passID = U_pick.chapterID, chapterLastRead = U_pick.chapterNumber, passtitle = mTitle };
var dbpath = Path.Combine(Windows.Storage.ApplicationData.Current.LocalFolder.Path, "Drive.db");
using (var db = new SQLite.SQLiteConnection(dbpath))
{
try
{
var lastReadChapter = (db.Table<LastRead>().Where(c => c.passtitle == mTitle)).SingleOrDefault();
if (lastReadChapter != null)
{
lastReadChapter.chapterLastRead = U_pick.chapterNumber;
lastReadChapter.passtitle = U_pick.chapterTitle;
lastReadChapter.passID = U_pick.chapterID;
db.Update(lastReadChapter);
}
else
{
db.Insert(dataref);
}
}
catch(Exception ex)
{
//excepetion msg
}
}
这是因为您要通过SingleOrDefault()函数进行查询。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.