: http://dev.mysql.com/downloads/connector/net/
Installation Instructions
1. Installation: Mysql-connector-net-6.10.4.msi
it: http://dev.mysql.com/downloads/connector/net/
Install Mysql-connector-net-6.10.4.msi on WINDOWS10 operating system
The default is installed on the C drive:
After installation, reference the component MySql.Data.dll in the application engineering.
Then reference the component in the Application project: MySql.Data.dll.
2. The installation steps are as follows:
After the installation is complete C:\Program Files (x86) \mysql\mysql Connector Net 6.10.4\assemblies\v4.5.2
MySql.Data.dll is C # operation MySQL driver file, is C # connection MySQL necessary plugin, make C # language more concise operation MySQL database. Then add a reference to the component in the project, enter the using MySql.Data.MySqlClient in the code page, and we'll be able to make a connection using the class library's function successfully.
3. Test procedure
Create a new C # console application named: CSharp call MySQL. Add a reference "MySql.Data.dll" in C #
Add code in Program.cs:
1 usingSystem;2 usingSystem.Collections.Generic;3 usingSystem.Linq;4 usingSystem.Text;5 usingMySql.Data.MySqlClient;//reference MySQL6 7 8 namespaceCSharp call MySQL9 {Ten class Program One { A Static voidMain (string[] args) - { - stringConstructorstring ="Server=localhost; User id=root;password=;D Atabase=company"; theMysqlconnection Myconnnect =Newmysqlconnection (constructorstring); - Myconnnect.open (); -Mysqlcommand myCMD =NewMysqlcommand ("INSERT INTO t_dept (name,year) VALUES (' JJJ ',", myconnnect); - Console.WriteLine (mycmd.commandtext); + if(Mycmd.executenonquery () >0) - { +Console.WriteLine ("Data inserted successfully! "); A } atMycmd.commandtext ="INSERT INTO t_dept (name,year) VALUES (' Jjj4 ',"; - Console.WriteLine (mycmd.commandtext); - if(Mycmd.executenonquery () >0) - { -Console.WriteLine ("Data inserted successfully! "); - } inMycmd.commandtext ="Delete from t_dept"; - Console.WriteLine (mycmd.commandtext); to if(Mycmd.executenonquery () >0) + { -Console.WriteLine ("User table type data all successfully deleted! "); the } * mycmd.dispose (); $ myconnnect.close ();Panax Notoginseng } - } the}
4. C # connection Database MySQL command
(1) Establish the connection:
New Mysqlconnection ("database= database name; The IP address of the data source= server; User id= username; password= User Password ");
Or:
New Mysqlconnection ("IP address of the server= server; user id= username; password= user password; database= database name ");
Or:
string " server= server IP address; User id= username; password= user password; database= database name "; // according to your own settings New Mysqlconnection (M_str_sqlcon);
Note: server= server IP address; User id= username, password= user password, database= database name, these order can be swapped, as long as the alignment of each string and identifier is good.
(2) Execute SQL command:
Set query commands
Mysqlcommand New Mysqlcommand ("select * fromt_dept wheretitlelike '%p% '" , Sqlcon);
C # calls the MySQL database (using MySql.Data.dll connection) Mysql-connector-net-6.10.4.msi