【问题标题】:Adapter not loading anything with SQLite C#适配器未使用 SQLite C# 加载任何内容
【发布时间】:2009-07-23 14:15:03
【问题描述】:

我使用此代码,SQLite 说“数据源不能为空。使用 :memory: 打开内存数据库”

这是我的代码

 string dbfile = new System.IO.FileInfo(System.Reflection.Assembly.GetExecutingAssembly().Location).DirectoryName + "\\m23.db";

        string sql;

        DateTime dt = DateTime.Now;
        SQLiteConnection connection = new SQLiteConnection("datasource="+ dbfile);

        SQLiteDataAdapter adapter = new SQLiteDataAdapter("select * from p_posts", connection);
        DataSet data = new DataSet();
        adapter.Fill(data); //  <<< here i get the error

        SQLiteCommand cmd = new SQLiteCommand();
        cmd.CommandType = CommandType.TableDirect;
        cmd.Connection = connection;

        connection.Open();

感谢任何帮助, 干杯!

【问题讨论】:

    标签: c# database sqlite


    【解决方案1】:

    尝试使用

    SQLiteConnection connection = new SQLiteConnection("Data Source=" + dbfile);
    

    我见过的examples 使用“数据源”而不是“数据源”。

    【讨论】:

      【解决方案2】:

      为避免此类参数语法问题,您还可以考虑使用SQLiteConnectionStringBuilder

      SQLiteConnectionStringBuilder con = new SQLiteConnectionStringBuilder();
      con.DataSource = dbfile;
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2021-07-01
        • 2020-06-10
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2016-03-11
        相关资源
        最近更新 更多