2015-10-06 51 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同一数据库路径中的所有其他实体,以及同一实体中其他查询的其他操作 –