使用MySQLDriverCS连接MySQL数据库
与使用MySQLConnectorNet大同小异,首先下载安装MySQLDriverCS后得到动态链接库文件:
http://www.easck.com/>
将MySQLDriverCS.dll添加到工程的引用中:
还是利用上买呢已经在MySQL数据库中建立了的测试数据,所以直接编写C#代码:
static void Main(string[] args)
{
MySQLConnection conn = new MySQLConnection(new MySQLConnectionString("127.0.0.1","student", "root", "root",3306).AsString);
conn.Open();
MySQLCommand cmd = new MySQLCommand("select * from stuinfo", conn);
DbDataReader reader = cmd.ExecuteReader();
while (reader.Read())
{
Console.WriteLine(reader.GetString(0) + " " + reader.GetString(1) + " " + reader.GetString(2) + " " + reader.GetString(3));//读出查询的结果
}
Console.ReadKey();
reader.Close();
conn.Close();//关闭连接
}
执行结果:
数据被成功读出。
注:相关教程知识阅读请移步到c#教程频道。













