2015-10-06 54 views
0

我有一個簡單的查詢,在名爲「CUSTOMER」的表中全選一個。Windows Phone的sqlite選擇全部

這是我的表:

public class CUSTOMER : Extension.Shared 
{ 
    [PrimaryKey, Indexed] 
    public Guid ID { get; set; } 
    [Indexed] 
    public string FULL_NAME { get; set; } 
    public string PHONE_NO { get; set; } 
    //public string PIVA_CF { get; set; } 
    public DateTime? MODIFIED_ON { get; set; } 

這是給我的問題

public List<CUSTOMER> SelectAll() 
    { 
     SQLiteConnection conn = new SQLiteConnection(DatabasePath()); 
     return conn.Query<CUSTOMER>("SELECT * FROM CUSTOMER"); 
    } 

每次運行此操作的查詢時,查詢將返回SQLite.cs文件的錯誤:

if (r != SQLite3.Result.OK) 
{ 
    throw SQLiteException.New (r, String.Format ("Could not open database file: {0} ({1})", DatabasePath, r)); 
} 

如果大小可以是一個有用的,這個表有近50000條記錄。 我在具有100000或80000條記錄的幾個表中遇到同樣的問題。 其他表沒有問題,其他查詢沒有問題。

我可以說這是因爲,因爲我覺得被嚴重保存在表中,我一次又一次表安裝,但我注意到,從同一個頁面,我可以把這個查詢沒有任何問題,所有表:

public List<CUSTOMER> SelectByFilter(string Filter) 
{ 
    SQLiteConnection conn = new SQLiteConnection(DatabasePath()); 
    return conn.Query<CUSTOMER>(string.Format("SELECT * FROM CUSTOMER WHERE FULL_NAME LIKE '{0}%'", Filter)); 
} 

我真的不知道這個錯誤從哪裏來。我不知道任何大小對Sqlite3的限制。任何幫助將不勝感激。

回答

0

這個錯誤告訴它在給定的路徑下找不到數據庫,使用獨立的存儲工具檢查數據庫是否存在於那個地方,同時檢查你是否在你的DatabasePAth()方法中引用數據庫文件的正確路徑,否則試試這個

public List<CUSTOMER> SelectByFilter(string Filter) 
{ 


    string dbpath = System.IO.Path.Combine(Windows.Storage.ApplicationData.Current.LocalFolder.Path, "yourdatabsefilename.db"); 
//database is in home directory not in any subfolders. then only this code will work 

    SQLiteConnection conn = new SQLiteConnection(dbpath); 
    return conn.Query<CUSTOMER>(string.Format("SELECT * FROM CUSTOMER WHERE FULL_NAME LIKE '{0}%'", Filter)); 
} 
+0

感謝您的回答,但我的問題是selectAll。我可以在沒有任何問題的情況下執行select同一數據庫路徑中的所有其他實體,以及同一實體中其他查詢的其他操作 –