Directly open.
1, only need to Mysql.data.dll download good after free place.
2, add a reference to the new project.
Browse to select the downloaded Mysql.data.dll address. After determination.
3, after the successful addition, the namespace will be able to enter the using MySql.Data.MySqlClient.
At this point, you can successfully connect to MySQL.
Steps:
<connectionStrings>
<add name= "Mysqlconnstr" connectionstring= "server=localhost;database=tset; User=root; password=****; Use Procedure bodies=false; Charset=utf8; Allow Zero datetime=true; Pooling=false; Max Pool size=50; "/>
</connectionStrings>
Configuration XML. As with SQL.
2. Get a database connection
<summary>
Get database connection
</summary>
<returns></returns>
Public Mysqlconnection Getconn () {
String connstr = system.configuration.configurationmanager.connectionstrings["Mysqlconnstr"]. ConnectionString;
Mysqlconnection = new Mysqlconnection (CONNSTR);
return mysqlconnection;
}
3. Perform data operations
<summary>
Execute Query
</summary>
<param name= "Commtext" ></param>
<returns></returns>
Public Mysqldatareader ExecuteNonQuery (String commtext) {
Mysqlconnection Mysqlcon = This.getconn ();
Mysqlcon. Open ();
Mysqlcommand Mysqlcommand = new Mysqlcommand ();
Mysqlcommand.connection = Mysqlcon;
Mysqlcommand.commandtext = Commtext;
Mysqldatareader mysqldatareader = null;
Try
{
Mysqldatareader = Mysqlcommand.executereader ();
}
catch (Exception ex)
{
}
Finally
{
Mysqlcon. Close ();
}
return mysqldatareader;
}
public void Executenullquery (String commtext) {
Mysqlconnection Mysqlcon = This.getconn ();
Mysqlcon. Open ();
Mysqlcommand Mysqlcommand = new Mysqlcommand ();
Mysqlcommand.connection = Mysqlcon;
Mysqlcommand.commandtext = Commtext;
Perform actions
Mysqlcommand.executenonquery ();
Mysqlcon. Close ();
}
over~
C # connect MySQL database from start to abort