首先在官网下载,mysql-connect-net,用于使用mysql的驱动程序,我在下载mysql-connect-net.msi. installer后,执行安装程序的时候一直无法安装成功,最简单的方法是直接下载.zip文件后解压,无须安装。
官网地址:http://dev.mysql.com/downloads/file/?id=463757
解压文件后,
出现了好几个文件夹,其中有v4和v4.5两个文件夹,对应vs的不同版本
VS2010使用V4.0下的dll文件
VS2012/2013/2015使用v4.5下的dll文件
其中有一个帮助手册十分有用:
Documentation文件夹下的ConnectorNET.chm中包含了连接mysql数据库的API。
MySqlConnection类用来连接数据库
Constructor:
构造函数
MySqlConnection(String) |
Initializes a new instance of theMySqlConnection class when given a string containing the connection string.
|
打开数据库
Open |
Opens a database connection with the property settings specified by the ConnectionString.
(Overrides DbConnection.Open().) |
关闭数据库
Close |
Closes the connection to the database. This is the preferred method of closing any open connection.
(Overrides DbConnection.Close().) |
请将项目文件中的“AutoGenerateBindingRedirects”属性设置为 true
这个可以找到vs该工程的文件夹下的csproj文件中增加<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
警告即可消除。
也可以参考该网址http://www.cnblogs.com/zoro-zero/p/5867320.html解决问题
constructor:
MySqlCommand(String, MySqlConnection) |
Initializes a new instance of theMySqlCommand class with the text of the query and aMySqlConnection.
|
MySqlCommand(String, MySqlConnection, MySqlTransaction) |
Initializes a new instance of theMySqlCommand class with the text of the query, aMySqlConnection, and theMySqlTransaction.
|
执行sql语句
ExecuteNonQuery |
Executes a SQL statement against the connection and returns the number of rows affected.
(Overrides DbCommand.ExecuteNonQuery().) |
设置或返回sql语句
CommandText |
Gets or sets the SQL statement to execute at the data source.
(Overrides DbCommand.CommandText.) |
参考:
http://blog.csdn.net/cfl20121314/article/details/27106819
http://blog.csdn.net/zhanghaoliangdehao/article/details/7372550
http://blog.csdn.net/apache6/article/details/2778878