• <legend id='oq7V1'><style id='oq7V1'><dir id='oq7V1'><q id='oq7V1'></q></dir></style></legend>

        <bdo id='oq7V1'></bdo><ul id='oq7V1'></ul>
    1. <i id='oq7V1'><tr id='oq7V1'><dt id='oq7V1'><q id='oq7V1'><span id='oq7V1'><b id='oq7V1'><form id='oq7V1'><ins id='oq7V1'></ins><ul id='oq7V1'></ul><sub id='oq7V1'></sub></form><legend id='oq7V1'></legend><bdo id='oq7V1'><pre id='oq7V1'><center id='oq7V1'></center></pre></bdo></b><th id='oq7V1'></th></span></q></dt></tr></i><div id='oq7V1'><tfoot id='oq7V1'></tfoot><dl id='oq7V1'><fieldset id='oq7V1'></fieldset></dl></div>

      <small id='oq7V1'></small><noframes id='oq7V1'>

      1. <tfoot id='oq7V1'></tfoot>
      2. Sqlite Window Phone 8 中的更新记录

        时间:2023-06-07

          • <small id='tphSW'></small><noframes id='tphSW'>

                <tbody id='tphSW'></tbody>
                <bdo id='tphSW'></bdo><ul id='tphSW'></ul>

              • <tfoot id='tphSW'></tfoot>
                <i id='tphSW'><tr id='tphSW'><dt id='tphSW'><q id='tphSW'><span id='tphSW'><b id='tphSW'><form id='tphSW'><ins id='tphSW'></ins><ul id='tphSW'></ul><sub id='tphSW'></sub></form><legend id='tphSW'></legend><bdo id='tphSW'><pre id='tphSW'><center id='tphSW'></center></pre></bdo></b><th id='tphSW'></th></span></q></dt></tr></i><div id='tphSW'><tfoot id='tphSW'></tfoot><dl id='tphSW'><fieldset id='tphSW'></fieldset></dl></div>
                  <legend id='tphSW'><style id='tphSW'><dir id='tphSW'><q id='tphSW'></q></dir></style></legend>
                • 本文介绍了Sqlite Window Phone 8 中的更新记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  限时送ChatGPT账号..

                  在我的数据库中,我有一个名为 question1 的表,初始默认状态分配为 = 0,然后每次我想更新时我都希望状态 = 1,我使用命令

                  In my database I have table named question1, with the initial default status assigned = 0, then every time I want to update I want the status = 1, I use the command

                  await conn.ExecuteAsync("UPDATE question1 SET Status = '1' WHERE id =" + ques1.id);
                  

                  但它不起作用.谁知道这里出了什么问题?下面是读取数据和更新表的代码......

                  but it is not working. Who knows what is wrong here? Here's the code to read the data and update the table......

                  public async Task<question1> get_data_question1()
                  {
                      SQLiteAsyncConnection conn = new SQLiteAsyncConnection("Database");
                      var query = conn.Table<question1>().Where(x => x.Status == 0);
                      var result = await query.ToListAsync();
                      question1 ques1 = new question1();
                      foreach (var item in result)
                      {
                          ques1.id = item.id;
                          ques1.Status = item.Status;
                      }
                      // Update
                      await conn.ExecuteAsync("UPDATE question1 SET Status = '1' WHERE id =" + ques1.id);
                      return ques1;
                  }
                  

                  推荐答案

                  这就是我设置简单数据库的方式.

                  This is how I would set up your simple database.

                  它将创建 3 个条目,所有状态 = 0.

                  It will create 3 entries with all Status = 0.

                  在代码中我说的那一行处设置一个断点;

                  Put a break point at the line where I said so in the code;

                  您会在该查询之后看到所有 0 值都已更新为 1.

                  You will see after that query all 0 values has been updated to 1.

                  using SQLite;
                  using System.IO;
                  using System.IO.IsolatedStorage;
                  using System.Threading.Tasks;
                  
                  public class Question
                  {
                      [SQLite.PrimaryKey, SQLite.AutoIncrement]
                      public int Id { get; set; }
                      public int Status { get; set; }
                  } 
                  
                  public partial class MainPage : PhoneApplicationPage
                  {
                      string dbPath = "";
                      public MainPage()
                      {
                          InitializeComponent();
                          dbPath = Path.Combine(Windows.Storage.ApplicationData.Current.LocalFolder.Path, "db.sqlite");                        
                  
                          CreateDBTable();
                          InsertDB();         // only call this once (comment it out the next time you deploy)
                          UpdateDB();
                  
                      }
                  }
                  
                  // from the MSDN example
                  private async Task<bool> FileExists(string fileName)
                  {
                      var result = false;
                      try
                      {
                          var store = await Windows.Storage.ApplicationData.Current.LocalFolder.GetFileAsync(fileName);
                          result = true;
                      }
                      catch
                      {
                      }
                      return result;
                  }
                  
                  public void CreateDBTable()
                  {
                      if (!FileExists("db.sqlite").Result)
                      {
                          using (var db = new SQLiteConnection(dbPath))
                          {
                              db.CreateTable<Question>();
                          }
                      } 
                  }
                  
                  public void UpdateDB()
                  {
                      using (var db = new SQLiteConnection(dbPath))
                      {
                          var existing = db.Query<Question>("SELECT * FROM Question WHERE Status = 0");
                          if (existing != null)
                          {
                              foreach(Question q in existing)
                              {
                                  db.Execute("UPDATE Question SET Status = 1 WHERE Id = ?", q.Id);
                              }
                          }
                  
                  
                          // query again to see if has changed
                          existing.Clear();
                  
                          existing = db.Query<Question>("SELECT * FROM Question WHERE Status = 1");
                          if (existing != null)
                          {
                              int breakpoint_here = 1;
                          }
                  
                      } 
                  }
                  
                  private void InsertDB()
                  {
                      using (var db = new SQLiteConnection(dbPath))
                      {
                          db.RunInTransaction(() =>
                          {
                              db.Insert(new Question() { Status = 0 });
                              db.Insert(new Question() { Status = 0 });
                              db.Insert(new Question() { Status = 0 });
                          });
                      }
                  }
                  

                  这篇关于Sqlite Window Phone 8 中的更新记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:为 Windows Phone 8 构建 SQLite 下一篇:有没有办法使用 SQL 获取有关服务器的信息

                  相关文章

                  最新文章

                  <tfoot id='ULlSM'></tfoot>
                    <legend id='ULlSM'><style id='ULlSM'><dir id='ULlSM'><q id='ULlSM'></q></dir></style></legend>

                      <i id='ULlSM'><tr id='ULlSM'><dt id='ULlSM'><q id='ULlSM'><span id='ULlSM'><b id='ULlSM'><form id='ULlSM'><ins id='ULlSM'></ins><ul id='ULlSM'></ul><sub id='ULlSM'></sub></form><legend id='ULlSM'></legend><bdo id='ULlSM'><pre id='ULlSM'><center id='ULlSM'></center></pre></bdo></b><th id='ULlSM'></th></span></q></dt></tr></i><div id='ULlSM'><tfoot id='ULlSM'></tfoot><dl id='ULlSM'><fieldset id='ULlSM'></fieldset></dl></div>

                      <small id='ULlSM'></small><noframes id='ULlSM'>

                      • <bdo id='ULlSM'></bdo><ul id='ULlSM'></ul>