我尝试连接到数据库MySql但出现此错误
FileNotFoundException was unhandled
在adapter.Fill
行中。
FileNotFoundException 未处理无法加载文件或程序集“Renci.SshNet,Version=2016.1.0.0,Culture=neutral,PublicKeyToken=1cee9f8bde3db106”或其依赖项之一。系统找不到指定的文件
class CONNECT
{
private MySqlConnection connection = new MySqlConnection("Datasource=localhost;Port=3306;Username=root;Password=;Database=Csharp_Hotel_DB");
//create a function to return our connection
public MySqlConnection getConnection()
{
return connection;
}
//create a function to open the connection
public void openConnection()
{
if (connection.State == ConnectionState.Closed)
{
connection.Open();
}
}
//create a function to close the connection
public void closeConnection()
{
if (connection.State == ConnectionState.Open)
{
connection.Close();
}
}
}
private void buttonLogin_Click(object sender, EventArgs e)
{
CONNECT conn = new CONNECT();
DataTable table = new DataTable();
MySqlDataAdapter adapter = new MySqlDataAdapter();
MySqlCommand command = new MySqlCommand();
String query = "SELECT * FROM `users` WHERE `username`=@usn AND `password`=@pass";
command.CommandText = query;
command.Connection = conn.getConnection();
command.Parameters.Add("@usn", MySqlDbType.VarChar).Value = textBoxUsername.Text;
command.Parameters.Add("@pass", MySqlDbType.VarChar).Value = textBoxPassword.Text;
adapter.SelectCommand = command;
adapter.Fill(table); //this line is the FileNotFoundException was unhandled
// if the username and the password exists
if (table.Rows.Count > 0)
{
this.Hide();
MessageBox.Show("YES");
Main_Form mform = new Main_Form();
mform.Show();
}
else
{
if (textBoxUsername.Text.Trim().Equals(""))
{
MessageBox.Show("Enter Your Username to Login", "Empty Username", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
else if (textBoxPassword.Text.Trim().Equals(""))
{
MessageBox.Show("Enter Your Password to Login", "Empty Password", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
else
{
MessageBox.Show("Username and Password Doesn't Exists", "Wrong Data", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
最佳答案
它现在正在工作c。
使用 MySQL-connector-net-6.3.5
可以修复此错误或问题,因为我使用的是 .net 4
感谢您的帮助。
关于c# - 在adapter.Fill(table)行中未处理文件未找到异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58180456/