当我尝试在具有 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/