c# - 如何引用指令MySql.Data.MySqlClient来连接mysql数据库

标签 c# mysql

当我尝试在具有 MySql 数据库的网络服务器中运行我的程序时,出现以下编译错误,

Compiler Error Message: CS0246: The type or namespace name 'MySql' could not be found (are you missing a using directive or an assembly reference?)

Source Error:

Line 2:  using System.Data;
Line 3:  
Line 4:  using MySql.Data.MySqlClient;
Line 5:  
Line 6:  namespace MySQL_test

下面给出的代码有什么问题,

using System;
using System.Data;
using MySql.Data.MySqlClient;

namespace MySQL_test
{
    class Program
    {
        static void Main(string[] args)
        {
            string connstring = 
                        @"server=localhost:3306;userid=abc123;
                                password=qMv87p3N2s;database=testDB";

            MySqlConnection conn = null;

            try
            {
                conn = new MySqlConnection(connstring);
                conn.Open();

                string query = "SELECT * FROM table_name;";
                MySqlDataAdapter da = new MySqlDataAdapter(query, conn);
                DataSet ds = new DataSet();
                da.Fill(ds, "table_name");
                DataTable dt = ds.Tables["table_name"];

                foreach (DataRow row in dt.Rows)
                {
                    foreach (DataColumn col in dt.Columns)
                    {
                        Response.Write(row[col] + "\t");
                    }

                    Response.Write("\n");                  
                }           
            }
            catch (Exception e)
            {
                Response.Write("Error: {0}", e.ToString());
            }
            finally
            {
                if (conn != null)
                {
                    conn.Close();
                }
            }
        }
    }
}

最佳答案

重建您的项目并上传所有 bin DLL,如果您已经这样做了,请重新引用 mysql.dll 来自您的项目/bin/debug/directory

关于c# - 如何引用指令MySql.Data.MySqlClient来连接mysql数据库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59508766/

相关文章:

c# - 使用 Azure 移动服务从多个表读取数据

php - 如何将带有mysql的php应用程序部署到heroku?

mysql - 如何在 JOIN MySQL 查询/操作中保留原始 ID?

c# - 我应该对 "latency-critical"线程使用线程关联吗?

c# - 如何使用NHibernate实现“保存/放弃”功能?

c# - "Csc"任务意外失败无法从程序集 mscorlib Version=4.0.0.0 加载类型 System.ValueTuple 3,

mysql - 使用 group by、where 和 'flag' 优化单表查询

c# - CsvHelper 在 VisualStudio 2013 中非常慢

mysql - 当我将内连接更改为左连接时,sql错误1064

php - mysql使用主键选择最后一个重复记录