参考文章:http://www.cnblogs.com/xiaohaikong/archive/2009/08/13/1544478.html
---------------------------------------------------------------------------------------------------------------------
MySQLDriverCS-n-EasyQueryTools-4.0.1-DotNet2.0.zip下载地址:
http://download.csdn.net/download/friendan/5497971
其实文中用到的MySQLDriverCS.dll文件,在我测试的例子程序中已经打包给大家了,
该例子程序在文章后面有下载地址。
-----------------------------------------------------------------------------------------------------------------------
其实C#连接MySQL数据库,不是很难,关键是要把MySQLDriver.dll导入到工程的引用中。
------------------------------------------------------------------------------------------------------------------------
先看下效果截图:
--------------------------------------------------------------------------------------------------------
主要代码为:
bool ConnMySqlDb()
{
try
{
MySQLConnection conn = null;
conn = new MySQLConnection(
new MySQLConnectionString(txbIp.Text.Trim(),
txbDb.Text.Trim(),
txbUser.Text.Trim(),
txbPass.Text.Trim()).AsString);
conn.Open();
MessageBox.Show("所连数据库为:"+conn.Database);
return true;
}
catch (System.Exception ex)
{
MessageBox.Show(ex.ToString() + ex.Message);
return false;
}
}
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
C#连接MySql例子程序.zip