2015-10-17 71 views
0

正如我在標題中所說的那樣,我寫的查詢沒有任何回退,而在Valentina Studio中檢查數據庫的工作正常,我不明白什麼是錯的。 下面的代碼:Windows Store應用程序中的SQLite查詢不會返回任何內容

using System; 
using System.Collections.Generic; 
using System.Text; 
using SQLite; 

namespace SQLite_Analizer 
{ 
    public class sqlite_master 
    { 
     public string name { get; set; } 
    } 

    public class manager 
    { 
     public List<string> GetListTables(string DBName) 
     { 
      List<string> tablesList = new List<string>(); 
      string itemName = null; 
      var con = new SQLiteAsyncConnection(DBName); 
      var query = con.QueryAsync<sqlite_master>("SELECT name FROM sqlite_master WHERE type='table' AND NOT SUBSTR(name,1,6) = 'sqlite' ORDER BY name").GetAwaiter().GetResult();   
      foreach(var tablesItem in query) 
      { 
       itemName = "\n" + tablesItem.name + "\n\n"; 
       tablesList.Add(itemName); 
      } 
      return tablesList; 
     } 
    } 
} 

這裏用一個計數器的新代碼來檢查查詢結果數。

using System; 
using System.Collections.Generic; 
using System.Text; 
using SQLite; 

namespace SQLite_Analizer 
{ 
    public class sqlite_master 
    { 
     public string name { get; set; } 
    } 

    public class manager 
    { 
     private List<string> tablesList; 
     private int count; 

     public manager() 
     { 
      tablesList = new List<string>(); 
      count = 0; 
     } 

     public List<string> getList() 
     { 
      return tablesList; 
     } 

     public int getCount() 
     { 
      return count; 
     } 

     public async void GetListTables(string DBName) 
     { 
      string itemName = null; 
      var con = new SQLiteAsyncConnection(DBName); 
      var query = await con.QueryAsync<sqlite_master>("SELECT name FROM sqlite_master WHERE type='table' AND NOT SUBSTR(name,1,6) = 'sqlite' ORDER BY name"); 
      foreach (var tablesItem in query) 
      { 
       itemName = "\n" + tablesItem.name + "\n\n"; 
       tablesList.Add(itemName); 
      } 
      count = query.Count; 
     } 
    } 
} 
+0

改變了代碼,但仍然沒有改變。 –

回答

0

我會嘗試這樣的事情

public async List<string> GetListTables(string DBName) 
    { 
     List<string> tablesList = new List<string>(); 
     string itemName = null; 
     var con = new SQLiteAsyncConnection(DBName); 
     var query = await con.QueryAsync<sqlite_master>("SELECT name FROM sqlite_master WHERE type='table' AND NOT SUBSTR(name,1,6) = 'sqlite' ORDER BY name");   
     foreach(var tablesItem in query) 
     { 
      itemName = "\n" + tablesItem.name + "\n\n"; 
      tablesList.Add(itemName); 
     } 
     return tablesList; 
    } 
相關問題