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)"
请帮忙。任何帮助将不胜感激,谢谢!
最佳答案
关于C#如何连接WPF和SQLITE数据库最简单的方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42336747/