为什么 SQLite 数据库值无法检索

本文关键字:检索 SQLite 数据库 为什么 | 更新日期: 2023-09-27 17:57:03

我尝试将一些数据存储到c#, XAML项目中。当我将数据添加到数据库中时。但是当我试图取回它们时,它没有发生。原因是什么。

用于存储值的代码值通过参数传递。它们是用户输入。

var DBPath = Database.DB_PATH;
using (var db = new SQLite.SQLiteConnection(DBPath))
{
      db.CreateTable<User>();
      db.RunInTransaction(() =>
      {
          db.Insert(new User()
          {
              userName = uName,
              password = pass,
              email = mail,
              country = countRy,
           });
      });
}
MessageBox.Show("Details Added");

检索值

var _user = db.Query<User>("select * from User").FirstOrDefault();
db.RunInTransaction(() =>
{
      if (getUserName.Text == (_user.userName))
      {
            MessageBox.Show("Welcome " + getUserName.Text);
            NavigationService.Navigate(new Uri("/Map.xaml", UriKind.Relative));
      }
      else
      {
            MessageBox.Show("Invalid Credentials");
      }});
}

为什么 SQLite 数据库值无法检索

您必须在

插入记录后提交更改。
插入记录后呼叫db.commit()

退出事务模式时,您需要CommitRollback ,以应用或还原更改。

在检索值之前,请确保在插入时调用db.Commit()