2017-02-20 98 views
1

wpf和sqlite的新手。我只想为我的项目建立一个内部数据库。我希望这个项目能够被别人使用,所以我不能使用mysql作为数据库。所以我搜索内部数据库并决定尝试sqlite。我发现教程,但他们真的很混乱。我熟悉数据库我知道查询,但现在我只需要知道什么是必要的事情来设置启动WPF和sqlite之间的连接。下面是我的代码(我创建了一个不同的类对我的sqlite的连接):C#如何连接WPF和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"); 
     } 
    } 

有了这个代码,我得到了一个错误说

“类型‘System.DllNotFoundException’未处理的异常发生 在System.Data.SQLite.dll其他信息:无法加载DLL 'SQLite.Interop.dll':指定的模块找不到 (从HRESULT异常:0x8007007E)。”

请帮忙。任何帮助将非常感谢感谢!

回答

0

遵循以下步骤:

  • 添加项目并将其命名为x64和x86 2个文件夹。
  • 添加SQLite.interop.dll为x64和x86分别(谷歌对于相同)
  • 在SQLite.interop.dll属性,设置 “生成操作” - >内容 和“复制到输出目录” - >如果更新,则始终复制/复制。
+0

我没有sqlite.interop.dll。互联网中的正确文件在哪里下载? –

+0

从Nuget安装时检查软件包目录。它将有SQLite.interop.dll –

相关问题