2014-03-24 120 views
0

在我的Windows Phone应用程序中,我使用的是Sqlite数据库。我能够检索数据,但在尝试添加/更新任何数据时出现“只读”异常。我使用下面的代码无法更新Windows Phone应用程序中的Sqlite数据库

public async void UpdateFavQuote(int quoteid, string option) 
     { 
      var connection = new SQLiteAsyncConnection(_dbpath); 

      if (option == "ADD") 
      { 
       await connection.ExecuteAsync("Update Quotes SET IsFav = 1 where _id =" + quoteid); 
      } 
      else 
      { 
       await connection.ExecuteAsync("Update Quotes SET IsFav = 0 where _id =" + quoteid); 
      }    

     } 

当我在我的模拟器/设备上运行的应用程序,它工作正常,但一旦应用程序被发布到店里,我开始得到错误。我尝试使用下面的代码,但也给出了相同的错误

public void UpdateFavQuote(int quoteid, string option) 
     { 
      var connection = new SQLiteConnection(_dbpath, SQLiteOpenFlags.ReadWrite); 

      if (option == "ADD") 
      { 
       connection.RunInTransaction(() => 
       { 

       connection.Execute("Update Quotes SET IsFav = 1 where _id =" + quoteid); 
       }); 
      } 
      else 
      { 
       connection.RunInTransaction(() => 
       { 
        connection.Execute("Update Quotes SET IsFav = 0 where _id =" + quoteid); 
       }); 
      }    
     } 

这也给出了同样的问题,一旦应用程序发布。任何帮助,将不胜感激。

+0

数据库在哪里?它需要在某个可写的地方(例如不在你的应用程序包中) – WiredPrairie

+0

@WiredPrairie它位于以下位置 - 私有静态只读字符串_dbpath = Path.Combine(Windows.ApplicationModel.Package.Current.InstalledLocation.Path,“ QuotesDB“); – Mako

+0

您不能保存回您的应用程序包。您需要将数据库复制到可以读/写的本地文件夹。 – WiredPrairie

回答

0

您不能写入应用程序包,因为它是只读的。您需要将数据文件复制到本地存储中,以使其变为可写。你可以按照样品here

相关问题