c# - 在adapter.Fill(table)行中未处理文件未找到异常

标签 c# mysql ado.net filenotfoundexception

我尝试连接到数据库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/

相关文章:

php - 多次使用绑定(bind)参数

mysql - Docker Wordpress 容器在约 30 秒后退出

php - 使用一张表将不同的 MIME 类型上传到数据库

c# - ASP.Net 复选框确认消息不起作用

c# - 不能在匿名类型中使用 sum

C#图表控件: X value of a horizontal bar chart is 0 for all points in the serie

c# - 如何从 id 数组中获取一组行?

c# - 负前瞻行为不符合预期

asp.net - 在数据访问层中共享连接和事务

c# - Microsoft.Jet.OLEDB.4.0 的替代方案,用于对 MDB 文件进行 64 位 Access