Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/336.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 无法在SQLiteAsyncConnection中转换数据库路径_C#_.net_Sqlite_Xamarin - Fatal编程技术网

C# 无法在SQLiteAsyncConnection中转换数据库路径

C# 无法在SQLiteAsyncConnection中转换数据库路径,c#,.net,sqlite,xamarin,C#,.net,Sqlite,Xamarin,我正在学习如何使用SQLite.Net.Async在移动设备上创建本地数据库。我正在一步一步地学习教程,但是我的数据库路径有问题。错误消息显示“参数1无法从字符串转换为System.Func SQLite.Net.SQLiteConnectionWithLock”。我很困惑,因为这段代码在教程示例中运行得很好 这是我的代码: using SQLite.Net.Async; namespace ToDoList { public class TodoItemDatabase {

我正在学习如何使用SQLite.Net.Async在移动设备上创建本地数据库。我正在一步一步地学习教程,但是我的数据库路径有问题。错误消息显示“参数1无法从字符串转换为System.Func SQLite.Net.SQLiteConnectionWithLock”。我很困惑,因为这段代码在教程示例中运行得很好

这是我的代码:

using SQLite.Net.Async;

namespace ToDoList
{
    public class TodoItemDatabase
    {
        readonly SQLiteAsyncConnection asyncdatabase;

        public TodoItemDatabase (string dbPath)
        {
            asyncdatabase = new SQLiteAsyncConnection(dbPath);
            //I haven't done further because I was stucked by dbPath error
        }
    }
}
示例代码运行良好:

using System.Collections.Generic;
using System.Threading.Tasks;
using SQLite;

namespace Todo
{
public class TodoItemDatabase
{
    readonly SQLiteAsyncConnection database;

    public TodoItemDatabase(string dbPath)
    {
        database = new SQLiteAsyncConnection(dbPath);
        database.CreateTableAsync<TodoItem>().Wait();
    }

    public Task<List<TodoItem>> GetItemsAsync()
    {
        return database.Table<TodoItem>().ToListAsync();
    }

    public Task<List<TodoItem>> GetItemsNotDoneAsync()
    {
        return database.QueryAsync<TodoItem>("SELECT * FROM [TodoItem] WHERE [Done] = 0");
    }

    public Task<TodoItem> GetItemAsync(int id)
    {
        return database.Table<TodoItem>().Where(i => i.ID == id).FirstOrDefaultAsync();
    }

    public Task<int> SaveItemAsync(TodoItem item)
    {
        if (item.ID != 0)
        {
            return database.UpdateAsync(item);
        }
        else {
            return database.InsertAsync(item);
        }
    }

    public Task<int> DeleteItemAsync(TodoItem item)
    {
        return database.DeleteAsync(item);
    }
}
}
使用System.Collections.Generic;
使用System.Threading.Tasks;
使用SQLite;
名称空间待办事项
{
公共类TodoItemDatabase
{
只读SQLiteAsyncConnection数据库;
公共TodoItemDatabase(字符串dbPath)
{
数据库=新的SQLiteAsyncConnection(dbPath);
database.CreateTableAsync().Wait();
}
公共任务GetItemsAsync()
{
返回database.Table().ToListAsync();
}
公共任务GetItemsNotoneAsync()
{
返回database.QueryAsync(“从[TodoItem]中选择*,其中[Done]=0”);
}
公共任务GetItemAsync(int id)
{
返回database.Table().Where(i=>i.ID==ID).FirstOrDefaultAsync();
}
公共任务SaveItemAsync(TodoItem项)
{
如果(item.ID!=0)
{
返回数据库.UpdateAsync(项);
}
否则{
返回数据库.InsertAsync(项);
}
}
公共任务DeleteItemAsync(TodoItem项)
{
返回database.DeleteAsync(项);
}
}
}

这是示例应用程序中使用的包

我注意到的第一件事是,您的工作示例使用的是SQLite,而您的非工作代码使用的是SQLite.Net.async。这是另一个问题。我以前尝试过使用SQLite包,但效果不如示例代码。因此,在研究了Google之后,我决定使用SQLite.Net.Async而不是SQLite,然后它成功了。因此,工作示例使用的是与非工作示例完全不同的包?好的,我将再试一次。包存储上有许多包共享相同的名称。已解决。我在一开始就尝试使用SQLite net PCL 1.3.1,但我甚至无法成功安装它。因此,我安装了另一个具有类似软件包名称的软件包,并且部分工作正常。在那之后,我使用了一个旧版本的SQLite net PCL 1.2.1,它工作了!!