Windows Store App中的SQLite查询不返回任何内容

时间:2015-10-17 14:29:05

标签: c# sqlite windows-store-apps

正如我在标题中所说的那样,我写的查询没有重复,而在Valentina工作室尝试检查数据库工作正常,我不明白什么是错的。 代码如下:

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;
        }
    }
}

1 个答案:

答案 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;
    }