2014-04-04 29 views
0

我跟着这个教程导入现有数据库http://wp.qmatteoq.com/import-an-already-existing-sqlite-database-in-a-windows-8-application/复制我的数据库项目文件和设置建设行动内容之后更新的SQLite数据库值,我复制数据库孤立storage.Now时我尝试更新数据库中的值,并查看我的绑定列表框的变化,我不是能看到changes.When我使用独立存储资源管理器,查看数据库,该值已在DB.But改变查询它不回到我的更新values.I正在使用这两种情况下相同的连接字符串。无法后importing-的Windows Phone

//copy DB from installation folder to isolated storage 
private async Task CopyDatabase() 
{ 
    bool isDatabaseExisting = false; 

    try 
    { 
     StorageFile storageFile = await ApplicationData.Current.LocalFolder.GetFileAsync("sample.db"); 
     isDatabaseExisting = true; 
    } 
    catch 
    { 
     isDatabaseExisting = false; 
    } 

    if (!isDatabaseExisting) 
    { 
     StorageFile databaseFile = await Package.Current.InstalledLocation.GetFileAsync("sample.db"); 
     await databaseFile.CopyAsync(ApplicationData.Current.LocalFolder); 
    } 
} 

//update the value 
dbConn = new SQLiteConnection(DB_PATH); 
       dbConn.Query<resources>(" update resources SET isFavorite = 'True' WHERE resourceId =" + rid); 
      } 
// Query database to populate list box 
    string DB_PATH = Path.Combine(ApplicationData.Current.LocalFolder.Path, "sample.db"); 
    private SQLiteConnection dbConn; 
    dbConn = new SQLiteConnection(DB_PATH); 
    List<resources> retrievedpdf = dbConn.Query<resources>("select * from resources where categoryId=" + noid + " AND typeId=1").ToList<resources>(); 
     pdflist.ItemsSource = retrievedpdf; 

enter image description here

我能够查看exploreer变化,但查询返回未经修改的值。

回答

0

有与查询的问题,我一直在更新字符串“true”,以在table..This一个布尔值是正确的查询int updateCount = dbConn.Execute("update resources SET isFavorite = 1,modifiedTime = DATETIME('now') WHERE resourceId =" + rid);

1

我希望查询中的一些更改对我有所帮助。

//Copy your database file From Installation folder to IsolatedStorage on App launching. 

//Change your update query bu below query 
int updateCount = dbConn.Execute("update resources SET isFavorite = 'True' WHERE resourceId =" + rid); 

//Change your select Query 
**Edits** 

List<resources> retrievedpdf = dbConn.Table<resources>().ToList().Where(x=>x.categoryId.Equals(noid) && x.typeId.Equals(1)).ToList(); 

//Assign ListBox ItemSource to null before assign actual source 

pdflist.ItemsSource = null; 
pdflist.ItemsSource = retrievedpdf; 
+0

当我改变我的选择query..I得到错误时,表不列入在当前上下文中存在 –

+0

@PrasannaAarthi我所做的更改。 – Jaihind

+0

Thankyou .. bt我仍然收到错误“bool不包含tolist()的defenition,当我尝试列表 retrievepdf = dbConn.Table ().ToList()。其中​​(x => x.categoryId.Equals(noid )&& x.typeId.Equals(1).ToList()); –

相关问题