从sqlite填充数据集

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了从sqlite填充数据集相关的知识,希望对你有一定的参考价值。

如何修改此功能。我想用它来填充来自sqllite的数据集。

错误

enter image description here



 public void fillDATASET( DataSet ds, string tablename, string query)
        {
            string dbPath = Path.Combine(
System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal),
        "Department.db3");
              var conn = new SQLite.SQLiteConnection(dbPath);
             using (Mono.Data.Sqlite.SqliteCommand cmd = new SqliteCommand(query, conn))// error conn 
            {
                using (var DataAdapterd = new SqliteDataAdapter(cmd))
                {
                    ds.Clear();
                    DataAdapterd.Fill(ds, tablename);
                }
            }
        }
答案

这是因为您使用了两个不同的库。

var conn = new SQLite.SQLiteConnection(dbPath); 

这里您在sqlite-net-pcl nuget中使用了该方法,

Mono.Data.Sqlite.SqliteCommand cmd = new SqliteCommand(query, conn)

这里要使用System.Data.SQLite.Core nuget中的方法。

所以您需要使用统一的。

例如(使用System.Data.SQLite.Core nuget):

using System.Data;
using System.Data.SQLite;

public void fillDATASET(DataSet ds, string tablename, string query)
    {
        string dbPath = Path.Combine(System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal),
    "Department.db3");
        var conn = new SQLiteConnection(dbPath);
        using (SQLiteCommand cmd = new SQLiteCommand(query, conn))// error conn 
        {
            using (var DataAdapterd = new SQLiteDataAdapter(cmd))
            {
                ds.Clear();
                DataAdapterd.Fill(ds, tablename);
            }
        }
    }

以上是关于从sqlite填充数据集的主要内容,如果未能解决你的问题,请参考以下文章

Coredata 性能——为只读数据集提供预填充的核心数据 sqlite db

当我从用户获取数据并将其保存到 SQLite 数据库中时,我应该怎么做才能使列表视图在片段中工作

Android 逆向使用 DB Browser 查看并修改 SQLite 数据库 ( 从 Android 应用数据目录中拷贝数据库文件 | 使用 DB Browser 工具查看数据块文件 )(代码片段

Android 逆向使用 DB Browser 查看并修改 SQLite 数据库 ( 从 Android 应用数据目录中拷贝数据库文件 | 使用 DB Browser 工具查看数据块文件 )(代码片段

无法从片段中的 SQLite 获取数据

如何在片段中访问 SQLite 数据到 ListView