具体步骤(已经最简便了):
1. 下载 libmysql.dll 和 MySQLDriverCS.DLL
将 libmysql.dll 拷贝进 C:\Windows\System32 下面
2. 在工程添加(选中工程右键,下面添加): MySQLDriverCS.DLL
3. 在工程上面引用: Using usingMySQLDriverCS;
--------------------------------------------------------
//增,删,改
MySQLConnection DBConn;
DBConn = new MySQLConnection(new MySQLConnectionString
("localhost", "super", "root", "123", 3306).AsString);
DBConn.Open();
// 执行查询语句
MySQLCommand DBComm;
DBComm = new MySQLCommand("insert into employee values
(null,'"+jobId+"','"+employeeName+"','"+sex+"','"+phone+"','"+salary+"','"
+pwd+"','"+date+"');", DBConn);
int a = DBComm.ExecuteNonQuery();
// 显示数据
try
{
if (a > 0)
{
MessageBox.Show("执行成功!");
}
else
{
MessageBox.Show("书写错误,或系统繁忙!");
}
}
finally
{
DBConn.Close();
}