C#如何连接WPF和SQLITE数据库最简单的方法

标签 c# wpf sqlite connection

wpf 和 sqlite 的新功能。我只想要我的项目的内部数据库。我希望这个项目能够被其他人使用,所以我不能使用mysql作为数据库。所以我搜索内部数据库并决定尝试sqlite。我正在寻找教程,但它们真的很令人困惑。我熟悉数据库,我知道查询,但现在我只需要知道启动 WPF 和 sqlite 之间的连接需要设置哪些必要的内容。下面是我的代码(我为我的 sqlite 连接创建了一个不同的类):

 sqlite class

 using System.Data.SQLite;
 namespace StartMyApps
 {
     class StartMyAppDb_sqlite
     {
       public SQLiteConnection myConn;
       public SQLiteCommand myComm;
       public SQLiteDataReader myReader;

       public void openConnection(string query)
       {
         myConn = new SQLiteConnection("Data Source=StartMyApplication.sqlite;Version=3;");
         myConn.Open();
         myComm = new SQLiteCommand(query, myConn);
         myComm.ExecuteNonQuery();
         myReader = myComm.ExecuteReader();
       }      
    }
 }

 Main class (has a button to trigger the connection and will pass a query)

   private void hide_btn_Click(object sender, RoutedEventArgs e)
    {
        sqliteDB.openConnection("select *from application where app_id='1' and app_name='chrome.exe';");

        bool hasAccount = false;
        while (sqliteDB.myReader.Read())
        {
            hasAccount = true;
        }

        if (hasAccount == false)
        {
            MessageBox.Show("Logged in");
        }

        else if (hasAccount == true)
        {
            MessageBox.Show("Username invalid");
        }
    }

使用这段代码我收到一个错误

"An unhandled exception of type 'System.DllNotFoundException' occurred in System.Data.SQLite.dll Additional information: Unable to load DLL 'SQLite.Interop.dll': The specified module could not be found. (Exception from HRESULT: 0x8007007E)"

请帮忙。任何帮助将不胜感激,谢谢!

最佳答案

我想这就是您要找的:Unable to load DLL 'SQLite.Interop.dll'

假设你有:

  • 已安装 SQLite(适用于 Windows 的正确版本)

  • 适当的引用文献

关于C#如何连接WPF和SQLITE数据库最简单的方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42336747/

相关文章:

c# - 字典值C#

c# - 在 WPF 中动态更改旋转动画

wpf - 如何更改 WPF TextBlock 中文本和下划线之间的距离?

java - 如何在每次启动应用程序时创建一个新的数据库

javascript - 错误 : Cannot find module '../node-v11-darwin-x64/node_sqlite3.node'

c# - Web API 根元素

c# - 如何获取 Internet Explorer 和 Firefox 选项卡的内存详细信息?

c# - MongoDB:在 C# 驱动程序中构建查询

Wpf 组合框可选默认项

java - android SQLITE 数据库应用程序在运行 getAllComments() 方法时在创建时崩溃