- VS tools have ready-made methods for oracle and sqlserver databases, but mysql also needs to operate by itself
download mysql reference file
Download link: http://pan.baidu.com/s/1bpg0Tl1 Password: bfed
Add a mysql reference file to the project
Right-click on the project as shown in the figure below:
Click "Add Reference"
, click "Browse" in the dialog box to find the reference file, and click OK. After the addition is complete, open the "Reference" in the project, as shown in the figure below, the reference added in the
red box is
connect database code
code show as below:
...
using MySql.Data.MySqlClient
...
string conn = "server=localhost;user id=root;password=123456;database=test";
MySqlConnection mysql_conn = new MySqlConnection(conn);
mysql_conn.Open();
string sql = "insert into student values('11','22')";
MySqlCommand mysql = new MySqlCommand(sql, mysql_conn);
int num = (int)mysql.ExecuteNonQuery();
The specific functions do not need to be explained, the main attention:
* The two class names of MySqlCommand and MySqlConnection are enough.
* using System.Data.MysqlClient don't forget this sentence