楼主你好
我用mono连接mysql的时候出现
1.WARNING **: The class System.Data.Common.DbConnection could not be loaded, used in System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
2.TestExample_mysql.cs(20,20): error CS0246: The type or namespace name `MySqlConnection' could not be found. Are you missing a using directive or an assembly reference?
我的程序是参考
http://www.mono-project.com/MySQL
#mcs TestExample_mysql.cs -r:System.Data.dll -r:/home/amy/mono/related_software/MySql.Data.dll
using System;
using System.Data;
using MySql.Data.MySqlClient;
public class Test
{
public static void Main(string[] args)
{
string connectionString=
"Server=localhost;"+
"Database=sysinfo;"+
"User ID=root;"+
"Password=;"+
"Pooling=false";
IDbConnection dbcon;
dbcon = new MySqlConnection(connectionString);
dbcon.Open();
IDbCommand dbcmd = dbcon.CreateCommand();
string sql = "SELECT firstname, lastname " +
"FROM employee";
dbcmd.CommandText = sql;
IDataReader reader = dbcmd.ExecuteReader();
while(reader.Read()) {
string FirstName = (string) reader["firstname"];
string LastName = (string) reader["lastname"];
Console.WriteLine("Name: " +
FirstName + " " + LastName);
}
// clean up
reader.Close();
reader = null;
dbcmd.Dispose();
dbcmd = null;
dbcon.Close();
dbcon = null;
}
}
第一个错误,是因为我的mono没安装好吗?
第二个,我gacutil -i MySql.Data.dll,并且using的
呵呵,谢谢了!